Thread: How To Generate Audio Data From A Wav File

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    4

    How To Generate Audio Data From A Wav File

    Hi,

    I've spent the past two evenings installing SDK's, trying out examples and googling the net so now I have decided to directly ask for help:

    I am looking for a means of obtaining audio sample data from a given wav file. This will permit me to write filters (such as compress, delay etc...) by manipulating the raw audio data in its waveform...the reason I need explicit access to the waveform data is to perform operations on it via the CPU and GPU.

    If you know of any such functions already built into the likes of DirectAudio, e.g GetSampleData
    or something then that'd be pretty sweet. Or if you know of a different library that offers such functionality that'd also be sweet. Basically any c++ sound library that offers data manipulation and goes beyond SoundPlay() SoundStop() or hardcoded filters like SoundChorus() etc..

    P.S I believe sdl_sound (via Sound_Sample* name) is capable of doing this but the SVN is down so if anybody has access to the latest Win32 build that might be of great help!

    Kindest Regards,
    Chu

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Try DirectShow. You could write a filter to handle data samples downstream.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    It might be easier to just use the sample grabber and SampleCB callback functionality so that you can directly edit the sample prior to it being pased to the rendering filter, which can be a file writer.

  4. #4
    Registered User
    Join Date
    Mar 2008
    Posts
    4
    Thanks for the replies.

    I'll look into your suggestion abachler, if I can point to the waveform in memory after its been read and decoded then that'd be ideal.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    WAV doesn't need to be decoded. Once you've read the header and determined the exact format, it's pretty much plain samples from there on. Maybe a RIFF block header every now and then. The Win32 multimedia API contains the necessary functions to deal with those.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by CornedBee View Post
    WAV doesn't need to be decoded.
    That assumes its PCM, which is not always the case. Directshow will work with compressed WAV's and MP3's as well. If youa re using PCM then yes, its much easier to just read t he sampels in yourself, uncompressed WAV is very simple.
    Last edited by abachler; 03-05-2008 at 02:51 PM.

  7. #7
    Registered User
    Join Date
    Mar 2008
    Posts
    4
    I'm dealing with uncompressed wav from the offset so thats fine. I'm failing to find a function in the Win32 multimedia API that will enable me to point to and process the waveform...I guess I'll have to try and hunt down a sdl_sound win32 build so I can use the sound_sample function.

  8. #8
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    if its 44100 16 bits per sample steroe, then you can just skipo the header and then alternately read the left adn then teh right channel data in until you hit feof(). A simple loop that fread()'s or ReadFile()'s will do it.

    or was it right adn then left I forget

  9. #9
    Registered User
    Join Date
    Mar 2008
    Posts
    4
    Cheers abachler I'll give that a try when I'm home.

    Just in case somebody has anything similar, here's what I'm after:

    http://icculus.org/SDL_sound/docs/ht...d__Sample.html

    As I say I can't get hold of the build (svn is down on their site) - it would be nice to have a function like that in an up to date library like directx.

    I'll give abachlers advice a try anyway.

    Regards,
    chu

  10. #10
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by abachler View Post
    if its 44100 16 bits per sample steroe, then you can just skipo the header and then alternately read the left adn then teh right channel data in until you hit feof(). A simple loop that fread()'s or ReadFile()'s will do it.

    or was it right adn then left I forget
    You should first find chunk of type "data", wave standard allows storing any number of other chunks between header and data
    Moreover - data chunk aloowed to be not alone... It is not to hard to implement fullystandard compatible procedure that will read wave-data... wave format is not too complex to suppose from the beggining that you need to implement it partially for simplisity.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  11. #11
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    I'm dealing with uncompressed wav from the offset so thats fine.
    You can find the WAV file specs at wotsit.org. Just make sure that your program reads and decodes the header file so it can and gracefully warn you if you run-into a file-configuration that the program can't handle . (i.e. Compressed files, 8-bit mono files, or whatever formats you decide not to support.)

    P.S.
    Once you have the WAV spec in-hand, it might also help to look at your WAV file with a hex editor. You should see the text "RIFF" and "WAVE". You should be able to mentally decode the header (at least some of it), and you should see the start of the data so you can compare the first few bytes/words with what your program is reading.
    Last edited by DougDbug; 03-06-2008 at 03:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Editing a data file
    By Strait in forum C++ Programming
    Replies: 7
    Last Post: 02-05-2005, 04:21 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 06:44 PM