Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Is there a way to separate the left and right channels from a stereo sound?

Author
Message
meb
15
Years of Service
User Offline
Joined: 14th May 2011
Location: United States
Posted: 14th May 2011 21:35
Hello.
I'm working on a project where the program need to record 5 seconds of stereo sound from the Line Input and then separates the recorded sound into it its left and right channels. I then need to do some comparisons between the channels (like power and FFT).

I am able to record the sound using RECORD SOUND and then save the recorded sound into a MEMBLOCK (MAKE MEMBLOCK FROM SOUND) - but now I'm kind of stuck.

Does anyone have any suggestions on how I might parse the memblock data into the separate channels so that I can assign them to arrays? Once the data has been put into an array I can handle coding the comparisons.

Thank you in advance for any help.
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 14th May 2011 23:43
Hi meb,

The help files refer to the Windows SDK WAVEFORMATEX structure. You might want to check it out for information on how to extract the sound data. I know that the data is either one (or sometimes two) bytes each sample. Considering you want to find the fourier transform, you'll probably want to convert them to floats first.

As for Power/FFT: Do you have a plugin or something that can do that? I think it's safe to say that Fourier Transforms (and so FFT as well) can be considered a higher level subject.

Cheers!
Sven B

Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 15th May 2011 16:02
In the memblock, I believe the sound sample data is stored like so, following the 28 byte header:
<sample 1, channel 1>
<sample 1, channel 2>
....
<sample 2, channel 1>
<sample 2, channel 2>
...

You can find out the size of each sample (usually a word for 16-bit sounds or a byte for 8-bits) from the header, which corresponds to the WAVEFORMATEX structure, as Sven B said.
However, in the memblock header, each part of the afforementioned structure is represented using a DWORD. So the header is as follows:


So, to do what you are aiming for, you would look at the memblock header to find the size of each sample and where the actual sample data starts. After that you would go through the sample blocks one by one, in which each channel has its own sample value stored, and assign these to your arrays.


"Why do programmers get Halloween and Christmas mixed up?"
meb
15
Years of Service
User Offline
Joined: 14th May 2011
Location: United States
Posted: 16th May 2011 23:54
Thank you both so much! This information is really helpful! If I can get a working app running I'll post it here. Thanks again!
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 17th May 2011 15:36
Isn't line in a mono signal anyway?

standard sound card line in is gonna be mono. unless its a recording device with Left and right mono channels which record to one wave, eg spdif or asio LR input assigned through software.

even if its saved as a stereo wave it will be two of the same mono file.

I cant really help, but I might be able to save you some time wondering why you cant detect differences between your stereo channels.
kezzla

Sometimes I like to use words out of contents
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 17th May 2011 16:14
I'm sure that DBPro doesn't even care if the sound is mono or stereo - it just plays it stereo.

Like if you load a mono file, it will play as if it's stereo - so double the frequency - because when I use mono sounds, they play at twice the speed. So as far as DBPro is concerned, it's probably best to stick to stereo sounds, even if they are just mono - at least then DBPro won't be making it's own mind up about frequency. I'm not sure if things are different with 3D sound, as that uses mono sound files as standard.

Health, Ammo, and bacon and eggs!
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 17th May 2011 16:30
From messing around with sounds and memblocks for my space invaders compo entry. I found you could easily change the frequency to the correct speed by altering the header file. I used mono samples to attempt to keep the data down when I converted it to code. It was still a whole LOT of data lol.

http://s6.bitefight.org/c.php?uid=103081
meb
15
Years of Service
User Offline
Joined: 14th May 2011
Location: United States
Posted: 18th May 2011 03:54
OK! Well, thank you again everyone!

Kezzla pointed out that the line-in is mono - so I really wanted to confirm that. First I created a stereo WAV file that has tones alternating on the left and right channels. When I play this WAV file I can clearly here the tone in only one speaker at a time. I then set one of my computers to play back this WAV file in an endless loop and connected a stereo audio cable from the computer speaker jack to the line-in on my DBPro development computer. Using Audacity, I can record the stereo sound coming in on the line-in, and play it back in stereo, so that's good. The ability for a program to record a stereo sound from the line-in exists.

However - when I use the same set up, but use a small DBPro program to record from the line-in (RECORD SOUND) and then play that sound back, it is, in fact a mono sound (ie I can hear both tones on both speakers simultaneously). So, it seems that DBPro does not RECORD in stereo.

Have other people had this experience - or am I doing something wrong?

Are there any know work arounds so that one can get DBPro to record a stereo sound?

Thanks again!

meb
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 19th May 2011 02:38 Edited at: 19th May 2011 02:38
This should record in stereo, provided your input device supports that (actually it will probably just record two identical sound channels if it doesn't). It's a bit ugly though (it requires that a wave file is saved, which you can then load (and delete, if needed), for one thing), but it should probably do what you're after




"Why do programmers get Halloween and Christmas mixed up?"
meb
15
Years of Service
User Offline
Joined: 14th May 2011
Location: United States
Posted: 20th May 2011 18:07
Hi!
Rudolpho - That worked! Thanks!

And thanks to everyone who posted. Although I have been using Game Creator products for a number of years, this is the first time I have posted to the forum - all the feedback has been great and really helpful.

Best,
meb

Login to post a reply

Server time is: 2026-07-10 21:41:53
Your offset time is: 2026-07-10 21:41:53