Rockbox Development > Starting Development and Compiling
How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in advance
timevision:
Hi guys/gal?,
I'm writing a Rockbox plugin that controls some hardware via the audio earphone port. My initial Rockbox target is an iPod Video, then a Sansa, maybe more later. I'm now stuck at getting to actually play the WAVE files (for 3 days already...). I'm currently studing Electrical Engineering, haven't touched C for 2, 3 years and it shames me to no end having to ask and not able to figure it out myself...
I've already searched most (if not all) forum threads, wiki, and available docs on this site.
Q1: How do I use PCM_PLAY_DATA correctly to play an existing WAVE file?
Q2: Am I on the right track? iPod seems to use SWCODEC, so PCM_PLAY_DATA is what I should use right?
It only needs to play WAVE files (just standard stereo WAVE, 44100Hz, 16bits). All the wave files I'm planning to play are extremely short, like 0.5 second or 2 seconds long max (don't know if it matters, just writing all the facts). I'm developing using Ubuntu on VMWARE inside a Windows Vista.
I looked all over the source code tree, figured out how to make menus, control music playback, print messages, etc, but I still doesn't know how exactly to play a file directly in a plugin.
I was hoping to find a MUSIC_PLAY(CHAR* PATH_TO_FILE) kind of function, but it seems the most "high level" functions that involves audio playback are "pcm_play_data" and "mp3_play_data" functions provided by PLUGIN.H.
My understanding to these functions are that they are constantly reading a BUFFER, and needs another function like GET_MORE to constantly fill it, it also needs to know the size of the data, but I'm not too sure how to fit them together and implement them.
I grep'ed and saw that a lot of plugins do make use of PCM_PLAY_DATA, but every plugin implement it a bit differently, It's not as simple and straight forward as DO_MENU or SPLASH, hehe. It's a little beyond my tiny C skills. (crap, I did pass the courses, didn't I?)
So, any help would be REALLY appreciated, I'm not the kind of person that just begs for code without thinking, any hint that can help me understanding these functions in more details will do. My ultimate goal is to be able to write a function that take a path to a WAVE file as argument, and plays it inside a plugin. Thank you very much from Toronto, Canada.
gnu:
This should give you a basic idea on how PCM playback works in rockbox:
http://www.rockbox.org/twiki/bin/view/Main/RockboxPCMPlayback
It's quite outdated, but you can see "working" PCM playback in many plugins (especially the metronome plugin).
By the way: you shouldn't use abbreviations like "thank u" here ;)
Domonoky:
As far as i know pcm_play_data(..) just plays raw pcm (44khz,16bit, stero interleaved ??) data.
So you have to open your wavefile, strip the waveheader (maybe convert the format) and pass it to the pcm_play_data() function.
Also if your wavefiles are short, so they fit into a buffer of yours, you can leave out the "getMore()" callback.. (replace it with NULL, as it is done in metronome.c).
timevision:
Thank you guys very much, Gnu and Domonoky. I have managed to duplicate Metronome's wave play function on my plugin and control it at will.
However, I'm still only using the sound sample data provided by Metronome.h.
I found all the buffer operations such as BUFOPEN, BUFGETDATA, & BUFCLOSE in plugin.h so I think I should be able to read my short WAVE files.
By the way, how large (how many seconds roughly) can these audio buffer support without using GET_MORE to re-fill it? Just want to know to be on the safe side.
Does anyone know how exactly would I convert raw binary WAVE data into the numerical SNDBUF as in Metronome.c?
Thank you all in advance again...
nls:
--- Quote from: timevision on June 10, 2008, 02:53:32 AM ---By the way, how large (how many seconds roughly) can these audio buffer support without using GET_MORE to re-fill it? Just want to know to be on the safe side.
--- End quote ---
If you steal the audio buffer from the playback engine it is roughly 30 MB on an ipod video 30GB and roughly 62 MB on a 60/80GB, the buffer space you can use in the plugin without stealing the audio buffer is 512kB (some of this is taken by your plugin itself).
rac pcm 16 bit 44.1kHz stereo takes 176,4 kB per second (1411 kbps)
--- Quote from: timevision on June 10, 2008, 02:53:32 AM ---Does anyone know how exactly would I convert raw binary WAVE data into the numerical SNDBUF as in Metronome.c?
--- End quote ---
IIRC wave is just raw little endian pcm with a header so strip the header, and read it into a buffer. Checking out some code that does wave reading such as the wav codec might be a good idea.
Navigation
[0] Message Index
[#] Next page
Go to full version