Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Rockbox Ports are now being developed for various digital audio players!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in advance
« previous next »
  • Print
Pages: [1]

Author Topic: How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in advance  (Read 2230 times)

Offline timevision

  • Member
  • *
  • Posts: 4
How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in advance
« on: June 09, 2008, 03:42:29 AM »
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.
« Last Edit: June 09, 2008, 03:49:02 AM by timevision »
Logged

Offline gnu

  • Member
  • *
  • Posts: 269
Re: How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in advance
« Reply #1 on: June 09, 2008, 11:36:13 AM »
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 ;)
Logged

Offline Domonoky

  • Developer
  • Member
  • *
  • Posts: 205
Re: How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in adva
« Reply #2 on: June 09, 2008, 01:58:18 PM »

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).

 
Logged

Offline timevision

  • Member
  • *
  • Posts: 4
Re: How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in adva
« Reply #3 on: June 10, 2008, 02:53:32 AM »
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...
Logged

Offline nls

  • Developer
  • Member
  • *
  • Posts: 460
Re: How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in adva
« Reply #4 on: June 10, 2008, 12:00:24 PM »
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.

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?

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.
Logged

Offline gnu

  • Member
  • *
  • Posts: 269
Re: How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in advance
« Reply #5 on: June 10, 2008, 01:12:16 PM »
If you only want the wave files for rockbox plugins, you can save them as "RAW 16bit PCM" with Audacity. Then you don't need to strip the header.
Logged

Offline timevision

  • Member
  • *
  • Posts: 4
Re: How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in adva
« Reply #6 on: June 12, 2008, 10:32:25 AM »
Hi guys,

When I use BUFOPEN function in PLUGIN.H, it needs a data_type, to open & store it more efficiently I suppose. Just wondering what is the difference between the different kinds:

enum data_type {
    TYPE_CODEC,
    TYPE_PACKET_AUDIO,
    TYPE_ATOMIC_AUDIO,
    TYPE_ID3,
    TYPE_CUESHEET,
    TYPE_BITMAP,
    TYPE_BUFFER,
    TYPE_UNKNOWN,
};


I'm only using it to open small WAVE files, maybe maximum 1MB in size. Should I use TYPE_PACKET_AUDIO, or just TYPE_BUFFER or... ?

Thanks.
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  How to play a WAVE file in Plugin? How to use PCM_PLAY_DATA? Thank u in advance
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.083 seconds with 15 queries.