(SpaceNuts) #1

Maybe this has been answered before but could anyone explain exactly what I need to do if I want to draw a complete waveform of a sound.

I want to draw the graphical representation of the waveform, like you see in
many wave-editors. To do this you must go through the sound once completely.

I tried doing this with getWaveData, starting at position 0 and steeping up 1 sample at a time, the problem is getWaveData only returns values when the sound is playing. Is it possible to get the wavedata when the sound is not playing, just by stepping through every single sample manually?

Thanks in advance.

(stdev) #2

You will use the ‘ReadData’ function, after a call to SeekData (to set the starting byte position). However, if you’re just going to zip through the entire audio file–from byte 0 to byte N–you won’t even need to use SeekData.

  • SD

(stdev) #3

If you’re going to be working with small audio files, then ignore my suggestion. If you’re going to be working with large audio files opened in stream mode, then ignore Brett’s suggestion.

Last time I checked, the lock method can’t be used with streams.

  • SD

(SpaceNuts) #4

Thanks for all your suggestions, I will try them out.
What I am willing to do is display a waveform of a music file which is loaded
as a stream, mostly songs (flac, mp3, ogg, wav) with an average length of 4 minutes.

Thanks again.

(SpaceNuts) #5

Maybe this is a stupid question but if I allocate a buffer and read some data into it, what type is this, are these all bytes? And what do these bytes represent.
Are they in a 16bit Wave the left or right sample?

(SpaceNuts) #6

Nevermind I found it out myself.
For all other users:

Example a Stereo (2 channel) 44100hz 16bit PCM

  • 44100 samples for 1 second of sound
  • 16 bits per sample
  • 4 bytes per sample
  • 2 bytes for left channel data
  • 2 bytes for right channel data

the bytes are little-endian
sample 0 left channel value = byte[0] + (byte[1] * 256)
this value is a signed value (the first bit indicates positive/negative value)

lets take 1 sample as an example:

byte0   byte1   byte2   byte3
126     229     031     098

[ left      ]   [ right     ]
-06786          +25119

Hope this is helpful to someone.