About Store Forum Documentation Contact



Post Reply 
Recording sound into a file.
Author Message
Eric Offline
Member

Post: #1
Recording sound into a file.
Hello,
I'm trying to write a program which records sound into a raw, binary compressed file. I have no problem with reading that file but when writing to it I have one little problem. Let me explain:

1. I'm creating SoundCapture and starting writing into 'File recfile;' in Init():
Code:
if(!SoundCapture.create(null, 16, 1, 44100))Exit("Failed to capture sound");
if(!recfile.writeTry("Recorded sound")) Exit("Cannot write to recfile!");
recfile.write("Recorded sound");

2. In Update() after checking if the record's buffer is full I'm trying to write that buffer's data into 'recfile' with:
Code:
/* (samples = SoundCapture.size()/SIZE(short)) */
if((SoundCapture.pos()/SIZE(short))>=samples) // HERE
         if(!recfile.put(SoundCapture.data(), SoundCapture.size()))
         Exit("Cannot put into recfile!");

and HERE is the problem, I don't know when the record's buffer is full (that 'here' condition is never true) so I could 'Put()' that buffer's data into 'recfile'.

Have you got any ideas how can I solve this problem?
Thanks in advance.
Eri
ourgames.eu

P.S. What does the SoundCaptureClass::Update() function? The comment doesn't explain this to me clearly enough.

Regards,
Eric 'Eri' Przychocki
ourgames.eu
02-24-2014 11:33 AM
Find all posts by this user Quote this message in a reply
Eric Offline
Member

Post: #2
RE: Recording sound into a file.
UP. This is very important to me.

Regards,
Eric 'Eri' Przychocki
ourgames.eu
02-28-2014 09:12 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
RE: Recording sound into a file.
I recommend getting a license, I could provide some hints.
02-28-2014 09:27 PM
Find all posts by this user Quote this message in a reply
Eric Offline
Member

Post: #4
RE: Recording sound into a file.
Smart! pfft Dear Esenthel, if I'm able to record sound (which with capturing video are main features of my upcoming program) I'm calling my coworker to buy the license smile

Regards,
Eric 'Eri' Przychocki
ourgames.eu
(This post was last modified: 03-01-2014 10:42 AM by Eric.)
03-01-2014 10:40 AM
Find all posts by this user Quote this message in a reply
Eric Offline
Member

Post: #5
RE: Recording sound into a file.
Esenthel, as you can see I became Licensed Developer wink Waiting for hints!

Regards,
Eric 'Eri' Przychocki
ourgames.eu
(This post was last modified: 03-06-2014 04:20 PM by Eric.)
03-06-2014 04:19 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Recording sound into a file.
That's a good choice smile

The way to do this, is to monitor the sound capture progress very frequently (every frame), and think of the buffer as of 2 halfs.
Code:
Bool last_half=0;

in the monitor code do:
Bool cur_half=( buffer.pos >= buffer.size/2); // current half of the buffer
if(last_half!=cur_half)
{
   last_half=cur_half;
  // save the half of the buffer data to disk
}
03-06-2014 08:50 PM
Find all posts by this user Quote this message in a reply
Eric Offline
Member

Post: #7
RE: Recording sound into a file.
Thank you Esenthel, my program works perfectly. It's funny how simple ideas can solve problems. wink
04-03-2014 05:39 PM
Find all posts by this user Quote this message in a reply
Post Reply