Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Combining recorded buffers.  (Read 3141 times)

0 Members and 3 Guests are viewing this topic.

ksneiders

  • Newbie
  • *
  • Posts: 9
    • View Profile
Combining recorded buffers.
« on: March 25, 2014, 12:21:01 pm »
I have been struggling with a problem..

I am creating a project that needs to record audio, and then combine two recorded sound buffers, so i can save it in a file.

I was reading this topic: http://en.sfml-dev.org/forums/index.php?topic=6970.0

And in the end the user provides a code... The code works perfectly on random .wav(using loadFromFile) files that i found. But when i use the buffer i recorded it doesnt work. It combines the two, but everything is just sped up.

So now i think there is a problem with the bitrate or sample rate of the files. But both the downloaded files and files recorded using SFML have the same Bitrate and Sample rate.

Can someone explain this? Or atleast any ideas what could be the problem here?
Thanks!

ksneiders

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Combining recorded buffers.
« Reply #1 on: March 25, 2014, 12:41:59 pm »
Ok, i found out that the Sample .wav file i was using had 8bits per sample. And the .wav recorded using SoundBufferRecorded has 16bits per sample.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Combining recorded buffers.
« Reply #2 on: March 25, 2014, 12:49:37 pm »
Quote
Ok, i found out that the Sample .wav file i was using had 8bits per sample. And the .wav recorded using SoundBufferRecorded has 16bits per sample.
It doesn't change anything, SFML loads it in 16-bit samples.
Laurent Gomila - SFML developer

ksneiders

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Combining recorded buffers.
« Reply #3 on: March 25, 2014, 12:58:08 pm »
It doesn't change anything, SFML loads it in 16-bit samples.

I see... But can you explain what am i doing wrong with the newly recorded 16-bit sample Buffers?

How do they differ from the ones loaded from file?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Combining recorded buffers.
« Reply #4 on: March 25, 2014, 01:08:02 pm »
Maybe something about the number of channels? Recorded sounds are mono (1 channel), whereas the other example uses 2 channels.

And what how does the size of the combined buffer relates to the size of the original ones? Is it half? twice? random?
Laurent Gomila - SFML developer

ksneiders

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Combining recorded buffers.
« Reply #5 on: March 25, 2014, 01:21:20 pm »
Maybe something about the number of channels? Recorded sounds are mono (1 channel), whereas the other example uses 2 channels.
Is there a way to go arround this? Like converting the mono buffer to a stereo?

So the array for a stereo buffer would be [s-left,s-right,s-left,s-right] ?

And mono? If it is just [s-mono,s-mono] couldnt i transform it into  [s-mono,s-mono-copy,s-mono,s-mono-copy] ?

Or am i understanding this completely wrong?

And what how does the size of the combined buffer relates to the size of the original ones? Is it half? twice? random?

Do you mean the file size?
I merged two recorded files. The file size of the two merged buffers is the same as the largest of the two.


ok, the SampleCount from the downloaded file is 93684 and the recorded one is  74970 although the recorded one is 2 seconds long but the downloaded is only 1 second long.

So, it must be the problem with the chanel count.

« Last Edit: March 25, 2014, 01:34:19 pm by ksneiders »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Combining recorded buffers.
« Reply #6 on: March 25, 2014, 01:33:07 pm »
Quote
Is there a way to go arround this? Like converting the mono buffer to a stereo?

So the array for a stereo buffer would be [s-left,s-right,s-left,s-right] ?

And mono? If it is just [s-mono,s-mono] couldnt i transform it into  [s-mono,s-mono-copy,s-mono,s-mono-copy] ?

Or am i understanding this completely wrong?
You don't need to deal with stereo, just produce a mono buffer from your two mono buffers. Combine the samples one by one, and don't forget to pass "1" instead of "2" to the loadFromSamples function. Don't overcomplicate the task ;)

Quote
Do you mean the file size?
I mean the buffer duration (that you can get with the SoundBuffer::getDuration() function).
Laurent Gomila - SFML developer

ksneiders

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Combining recorded buffers.
« Reply #7 on: March 25, 2014, 01:40:19 pm »

You don't need to deal with stereo, just produce a mono buffer from your two mono buffers. Combine the samples one by one, and don't forget to pass "1" instead of "2" to the loadFromSamples function. Don't overcomplicate the task ;)


Thank you so much. I feel really dumb now. :D

ps. SFML has really great customer support apparently!!!

 

anything