Hello, I am working on an iPhone app where I am recording audio. There is a record and stop recording button. The first time the app loads, and I record something then play it back, it is perfect. If I then goto record another recording, it is all messed up. It sometimes contains part of my previous recording, or just messes up the audio. Here are my record and stop recording methods:

[quote="mathew":zpoqu8fq]The FMOD::Sound that you record to is at its core just a buffer. It will not be wiped clean when you do another recording, so if the second record is shorter than the first you will still have the ‘left over’ recording in the part of the buffer that wasn’t written to.

If you want to wipe all or part of the buffer, use the Sound::lock and Sound::unlock feature to access the buffer, then memset the data to 0.[/quote:zpoqu8fq]

[quote="mathew":wq8enosf]You need to make sure that code doesn’t run once you have stopped the recording. Otherwise the record position will reset back to 0, and your code will write out from your last record position to 0.[/quote:wq8enosf]

I ended up fixing the timer issue, it was running basically the whole lifetime of the app since I was never invalidating it. What I did was start the timer in my start record, and invalidate it in stop record.

BUT….

The issue with "blank sound" after the first recording still exists and I have no idea why.

Below is my entire FMODController.mm if you wouldn’t mind taking a look at it.

As I said in one of the above posts:
[quote:1k00le7w]Are you resetting lastRecordPos when you start your next recording? If not that may explain why you get silence written out the length of the last recording.[/quote:1k00le7w]

When you do your second recording, lastRecordPos will still have its old value, you need to reset it in either stop or start.

I decided the easiest place to clear the buffer would be at the beginning of the record method, but I am having issues. I have yet to really use the lock or unlock functions, but I looked at examples and copied some code and I still can’t get it working. I get an error #37, "An invalid parameter was passed to the function."

[quote="mathew":1ngjqn06]As I said in one of the above posts:
[quote:1ngjqn06]Are you resetting lastRecordPos when you start your next recording? If not that may explain why you get silence written out the length of the last recording.[/quote:1ngjqn06]

When you do your second recording, lastRecordPos will still have its old value, you need to reset it in either stop or start.[/quote:1ngjqn06]

Finally! I believed I fixed it. I had attempted doing this when you first suggested it, but I at that point I was still having that timer issue. I think the combination of fixing both issues resolved the problem.

Thanks again for your continued help!

For licensing info I should direct my client to this e-mail correct: sales@fmod.org?

Firstly, sound->lock
– The second parameter is length in bytes, you need a meaningful value here, most likely the length of the sound (Sound::getLength).
memset
– You should be clearing the locked memory, not your buffer so:
[code:2jfo4j0r]
memset(ptr1, 0, len1);
memset(ptr2, 0, len2);
[/code:2jfo4j0r]
sound->unlock
– The first two parameters should be ptr1 and ptr2 to not &ptr1 and &ptr2.

[quote="mathew":3aj2izhn]Firstly, sound->lock
– The second parameter is length in bytes, you need a meaningful value here, most likely the length of the sound (Sound::getLength).
memset
– You should be clearing the locked memory, not your buffer so:
[code:3aj2izhn]
memset(ptr1, 0, len1);
memset(ptr2, 0, len2);
[/code:3aj2izhn]
sound->unlock
– The first two parameters should be ptr1 and ptr2 to not &ptr1 and &ptr2.[/quote:3aj2izhn]

I got it working, I am not hearing parts of old recordings in my new one. But I am still experiencing a ‘blank sound’ for the duration of the original one before my new recording plays.

Do I need to reset the position to the beginning of the sound or something?

Sound::recordStop should reset back to the start of the buffer. If you look at the recording example you’ll notice that when you press ‘stop’ the reported position snaps back to 0, then when you start again the position ticks up from 0. Perhaps you could post some more of your code?

[quote="mathew":q0ynqeg6]Sound::recordStop should reset back to the start of the buffer. If you look at the recording example you’ll notice that when you press ‘stop’ the reported position snaps back to 0, then when you start again the position ticks up from 0. Perhaps you could post some more of your code?[/quote:q0ynqeg6]

What does the variable RECORD_LENGTH_SECS = 3; determine? I tried changing that around and I get crashes. The max recording recording length allowed in the app is 30 seconds. I think thinking that this line might be the culprit, since there is usually about a 3 second delay before the actually recording begins to play (only on the 2nd recording not the first).

[quote="mathew":137gs92u]RECORD_LENGTH_SECS is the length of the record buffer in seconds, the larger the value the more memory will be used. However if you are using looping record, you won’t need to set it very large.

Are you resetting lastRecordPos when you start your next recording? If not that may explain why you get silence written out the length of the last recording.[/quote:137gs92u]

lastRecordPos is local to timerUpdate. I tried to bring it out to the class and reset it when the recording starts, but then I experiencing very strange recordings.

The FMOD::Sound that you record to is at its core just a buffer. It will not be wiped clean when you do another recording, so if the second record is shorter than the first you will still have the ‘left over’ recording in the part of the buffer that wasn’t written to.

If you want to wipe all or part of the buffer, use the Sound::lock and Sound::unlock feature to access the buffer, then memset the data to 0.