Hello FMOD Community.
I am having some difficulty in trying to stream sound that is playing in a channel to an external .WAV file. My attempts so far only allow me to do something like that from a sound object. None of the provided FMOD examples that I can find seem to offer insight into how this may be done.
I would greatly appreciate some assistance with this.
- Loffer asked 6 years ago
Thanks peter, that’s working fine for me now!
Though it’s a little bit of a case of one problem leading to another, hopefully this will be my final question.
I’ve noticed that the following line of code, though essentially to put the music into 44100 so I don’t get slowdown in the recording tends to mess up which sound is in what speaker.
[code:1nyh3p1q]result = system.setSoftwareFormat(44100, FMOD.SOUND_FORMAT.PCM16, 2, 0, FMOD.DSP_RESAMPLER.LINEAR);
With that code, one of my sounds can only be heard in the left speaker. When I take it away, I can hear the sound in both speakers.
I’m not understanding why that happens, if you could shed some light on that (especially since it’s probably really off-topic now) that would be fantastic.
The docs for setSoftware format say:
The number of output channels / speakers to initialize the soundcard to. 0 = keep speakermode setting (set with System::setSpeakerMode). If anything else than 0 is specified then the speakermode will be overriden and will become FMOD_SPEAKERMODE_RAW, meaning logical speaker assignments (as defined in FMOD_SPEAKER) become innefective and cannot be used. Channel::setPan will also fail. Default = 2 (FMOD_SPEAKERMODE_STEREO).
Take a look at the documentation for FMOD_SPEAKERMODE_RAW for more information.
Hi, thanks for greeting and help Peter!
I was having a little bit of frustration with a custom DSP so I managed to solve my problem in a different way to get what was in a channel streamed to a .wav file.
I have another problem though. I’d like to get two different sounds from two different channels (channel1, and channel2) now streamed into the .wav file at the one time. I’ve set it up so whatever is in FMOD.Sound sound1 is sent to the external .wav file.
If I try putting both channel1 and channel2 to play in sound1 object, the channel2 sound will be the only one that gets recorded.
How do I combine both channel1 and channel2 into sound1? Is a custom DSP the solution or is there an easier way? 😀
EDIT: I’d also like to add that variations to things in the channels (i.e. variation in volume) is not reflected in the recording based on sound1, though I’d like it to. I imagine this may be something a DSP can fix too, but I think I need to be set on the right path.
Channels are mixed together in channel groups so you need to get the sound data from the channelgroup. Again I would reccomend the custom DSP method. If you need help with that feel free to post sections of the code you need help with. Basically the approach would be to buffer the sounddata in the custom DSP, the downsample it to 16-bit and write it out to file, when the sound is complete write the wav header. The ‘recordtodisk’ example demonstrates how to write a wav file including the header.
Thanks yet again Peter!
It’s hard to think where to start in order to get the raw data from a custom DSP.
It seems the ‘recordtodisk’ example uses
[code:2s2pplhg]sound.@lock(lastplaypos * 4, (uint)blocklength * 4, ref ptr1, ref ptr2, ref len1, ref len2);[/code:2s2pplhg]
to get the raw data.
I’m not sure about which equivalent to use in a DSP to get the data from a channel as opposed to a sound object.
EDIT: Wait…that would be part of the downsampling to 16bit, wouldn’t it?
All good, I got it. I used this as a guide.
All the channels are now included in the recording. I have one more question: How does one exclude individual channels from being recorded in the DSP?
Any further help would be greatly appreicated.
The data coming through the DSP is interleaved and so is the data you’re writing to the wav file.
For example say there is stereo sound and you want to record the only the left channel you would take every other sample.
[code:nxjuxjdc]LRLRLRLRLRLR -> LLLLLL[/code:nxjuxjdc]
the loop inside the custom DSP would look something like:
[code:nxjuxjdc]for(int frame = 0; frame < length; ++frame)
for(int channel = 0; channel < numchannels; ++channel)
if (channel == (int)FMOD_SPEAKER_FRONT_LEFT)
Hi peter, thanks yet again for your quick response.
I’m getting an error when I try to compare ‘channel’ as an int, like in your example to FMOD.SPEAKER.
[code:27jmumi5]Error 1 Operator ‘==’ cannot be applied to operands of type ‘int’ and ‘FMOD.SPEAKER’
Is there something I would be missing? I don’t explicitly refer to channel inside my DSP, but rather inchannels and outchannels.
Please login first to submit.