|
hi
i'm try to find a code that record sound
i found 3 project before it, and are all horrible documentation
this is maybe, the more easier to understand and do it work..
but, i need a very, very simple example in console c++
if u can help me, i need just record and save
a simple example in console will be very helpfull
gratz
a computer science student (Brazil, Santa Catarina)
|
|
|
|
|
Hi,
Do you need a very simple example to record sound in
- raw PCM or
- MP3
format?
Additionally, the API used in the very simple example should be
- WinSDK or
- using classes from this article
?
Regards,
Ruslan
|
|
|
|
|
i need a console simple example
can be recorded in mp3, will be a good choise
i'll use this class with my app, using wxWidgets
i just need the main example, starting, encoding, and stop record
a example using the classes
if possible, in a console app
another stuffs i learn after it
tks for help me
-- modified at 19:38 Wednesday 15th August, 2007
|
|
|
|
|
Well, then it is really simple then.
Have a look at the "Examples" section in the article, point 3. "mp3Writer" is half of the job and the code below (between "try {...} catch ()") is the second half.
A. Here
CWaveINSimple& device = CWaveINSimple::GetDevice(strDeviceName);
you need the provide the name of the WaveIN device.
B. Here
CMixerLine& mixerline = mixer.GetLine(strLineName);
you need to provide the name of the line to record from (line of the device)
C. Here
mixerline.SetVolume(0);
you need to provide the volume level of the line.
REMARK: All three (strDeviceName, strLineName and volume level) you can hardcode as constants or read from the command line (up to you).
D. This line
device.Start((IReceiver *) mp3Wr);
starts the recording process.
E. This line
device.Stop();
stops the recording.
You can find all these in sources (top of the article), which also includes/contains "main" function of the console application provided as an example. The complexity there is just to handle command line parameters and print available in the system WaveIN devices and Lines of the selected device. Anything else is as described above.
Please let me know if you succeed or not with this, otherwise I will provide a simple during the weekend.
Regards,
Ruslan
|
|
|
|
|
i try compile your code
but get some errors
i'm using mingw32 compiler..
i dont have V6.0
look this error msg
[Linker Error] undefined reference to `mixerGetLineInfoA@12'
[Linker Error] undefined reference to `mixerGetLineControlsA@12'
[Linker Error] undefined reference to `mixerGetControlDetailsA@12'
[Linker Error] undefined reference to `mixerGetControlDetailsA@12'
and some others linker errors
|
|
|
|
|
To resolve those linkage errors you need to add 'winmm.lib' to your project. Possibly, with mingw32 the name of the lib is different, i have never used mingw32, but idea is you need to provide the proper lib to the linker.
Regards,
Ruslan
|
|
|
|
|
i dont know what is this winmm.lib
beyond that linker errors
a "sizeof type", without sizeof(type), easy to fix
and [Warning] `packed' attribute ignored
on line } BE_CONFIG, *PBE_CONFIG ATTRIBUTE_PACKED;
i really need a lib to record sound
since the last day i'm trying to find one.. but is hard
most of they need visual c
and i dont have the vc sdk.. just the bins..
pls help me
=/
|
|
|
|
|
Why don't you try using Visual Studio Express edition? Free to download from Microsoft and free of charge for home and academic usage.
Regarding
>>i dont know what is this 'winmm.lib'
It's not about coding this time. I guess you know what static linking means. So
- at the first step, development environment compiles the code and produces object files (.obj),
- at the second step, development environment links the obtained object files with the provided static libraries (.lib) and produces the final executable.
As you see, I wrote 'provided' which means you have to provide this, if you know how to use 'mingw32'. You need to understand and know these details and be able to apply them with the development environment you are using. As so, even if I provide you the simple code, you won't succeed building the .exe without this knowledge about 'mingw32'.
So, in this case you need to provide 'winmm.lib' for proper linking. Windows Media API (winmm.lib/WINMM.DLL) was introduced many years ago, it's a standard in Windows. I don't believe 'mingw32' doesn't have this static library (somewhere in the 'LIB' folder where 'mingw32' is installed). Even LCC (lightest C compiler) has it.
Regards,
Ruslan
|
|
|
|
|
ok, i downloaded the visual studio
set lots of lib, and its compiling
but, its hard to create my own code
your example use argc.. argv, is hard to understand
then, i tried it:
int main() {
const vector<cwaveinsimple*>& wInDevices = CWaveINSimple::GetDevices();
CWaveINSimple& WaveInDevice = CWaveINSimple::GetDevice(wInDevices[0]->GetName());
CHAR szName[MIXER_LONG_NAME_CHARS];
UINT j;
CMixer& mixer = WaveInDevice.OpenMixer();
const vector<cmixerline*>& mLines = mixer.GetLines();
for (j = 0; j < mLines.size(); j++) {
::CharToOem(mLines[j]->GetName(), szName);
printf("%s\n", szName);
}
mixer.Close();
CWaveINSimple& device = CWaveINSimple::GetDevice(wInDevices[0]->GetName());
CMixer& _mixer = device.OpenMixer();
::CharToOem(mLines[6]->GetName(), szName); //get Microphone
CMixerLine& mixerline = _mixer.GetLine(szName);
mixerline.UnMute();
mixerline.SetVolume(0);
mixerline.Select();
_mixer.Close();
mp3Writer *mp3Wr = new mp3Writer(); //here crashes
device.Start((IReceiver *) mp3Wr);
while( !_kbhit() ) ::Sleep(100);
device.Stop();
delete mp3Wr;
CWaveINSimple::CleanUp();
}
and get this error:
"This aplication has request the Runtime to terminate it in a unusual way.
Please contact the application's support team for more information"
=/
and i get this fopen warning:
'This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
|
|
|
|
|
You forgot about 'try {...} catch(...)'. Also don't forget that 'lame_enc.dll' must be in the same folder with the final '.exe' file. It looks like application is trying to load 'lame_enc.dll' and it can't find it. As so application is throwing an exception which is not caught and you get runtime error.
Try this code:
#include "stdafx.h"
#include "INCLUDE/mp3_simple.h"
#include "INCLUDE/waveIN_simple.h"
#include <conio.h>
class mp3Writer: public IReceiver {
private:
CMP3Simple m_mp3Enc;
FILE *f;
public:
mp3Writer(unsigned int bitrate = 128, unsigned int finalSimpleRate = 0):
m_mp3Enc(bitrate, 44100, finalSimpleRate) {
f = fopen("music.mp3", "wb");
if (f == NULL) throw "Can't create MP3 file.";
};
~mp3Writer() {
fclose(f);
};
virtual void ReceiveBuffer(LPSTR lpData, DWORD dwBytesRecorded) {
BYTE mp3Out[44100 * 4];
DWORD dwOut;
m_mp3Enc.Encode((PSHORT) lpData, dwBytesRecorded/2, mp3Out, &dwOut);
fwrite(mp3Out, dwOut, 1, f);
};
};
int main() {
char strLineName[] = "Microphone";
const UINT volume = 15;
try {
const vector<CWaveINSimple*>& wInDevices = CWaveINSimple::GetDevices();
CWaveINSimple& device = CWaveINSimple::GetDevice(wInDevices[0]->GetName());
CMixer& mixer = device.OpenMixer();
CMixerLine& mixerline = mixer.GetLine(strLineName);
mixerline.UnMute();
mixerline.SetVolume(volume);
mixerline.Select();
mixer.Close();
mp3Writer *mp3Wr = new mp3Writer();
device.Start((IReceiver *) mp3Wr);
while( !_kbhit() ) ::Sleep(100);
device.Stop();
delete mp3Wr;
}
catch (const char *err) { printf("%s\n",err); }
CWaveINSimple::CleanUp();
return(0);
}
|
|
|
|
|
very tks!!!
this sample work
and i get the lame_enc.dll
i had forget
very tks
|
|
|
|
|
Hi,
I wish you make the dialog base app. example to use mp3 class as,I have tried to make it several times but it did not success.
If possible,please show me the dialog base sample.
I'm a novice.
Thank you.
Arun
|
|
|
|
|
Hi Arun,
Unfortunately I can't. Dialog based version is a commercial project:
http://mp3r.send2.me.uk/
Regards,
Ruslan Ciurca
|
|
|
|
|
Hi Ruslan,
OK,I understand but,I want to implement some point like mp3 recording with microphone or other into my learning project.
If you can suggest a little guide to do this,please suggest too.
Thank you.
Arun
|
|
|
|
|
Hi Arun,
Well, it depends on what are you novice to:
- programming in general
- C++
- MFC
- MP3 encoding
This also depends on what and how you plan to implement, general application's approach/design. You can also have a look at what/how other people implemented similar things.
Application's approach is important. Anything else is just technical solution(s) (well, sometimes difficult to implement, but at least you know what you want to achieve). And, due to the lack of time, I can help you only just by answering specific technical questions.
Regards,
Ruslan Ciurca
|
|
|
|
|
Hi Ruslan,
Thank you for your suggestion.I would be spending the time for this surely but,at least like you said i know what i want to achive.
Thank you.
Regards,
Arun
|
|
|
|
|
Hi,
Let me first congratulate you for writing such a useful tool. I was wondering if the lame_enc.dll can be included in an installer of a freeware tool?
Thanks,
Sumit
Sumit
|
|
|
|
|
Hi Sumit,
Lame project is an open source one. The only restriction is the Light GPL (LGPL) license.
More details here:
http://lame.sourceforge.net/license.txt
Skip the decoding part, because the classes in this article do only encoding.
Regards,
Ruslan Ciurca
|
|
|
|
|
HI Ruslan,
This is Mujeeb Again, Once again Thanks for your excellent comment on "Recording from Simultanious Sources"
Now I am trying to use your Mp3_stream for realtime mp3 recording in my application, As I am really new to C++ i just can;t change ur code to meet my requirement.
My Request is quite simple.
1.How can i use default audio device (with out specifying name) for recording.
2. "From where i will get a C# sample for implimentation of lame.exe for Real-Time mp3 encoding", Do you have any idea?
Thanks
Mujeeb
|
|
|
|
|
Hello Mujeeb,
Regarding request 1, I haven't implemented this feature. Low level Wave API doesn't have the notion of the default device (within the API), so, as far as I know, this is resolved a bit different. I have posted an answer to this, see topic related to 'windows default mixer' ... so you can find default device by querying registry, path:
HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Sound Mapper\Record
Following this path, you will extract the name (string) of the system's default recording device. With that name ... use CWaveINSimple::GetDevice(...) next.
Regarding request 2, ... well, first I suggest googling. By the way, few month ago I found a Lame wrapper for Java (tritonus) which I used for a voice chat, so, I am 99% sure there should be one for C#. You can start with sourceforge. If not, check this FAQ for the very first posts, you will see 'play File' topic with few links. I mean guys maintaining madxlib, they have few applications in C#. One application they have done allows re-coding sound from WAV to MP3 (and I think vice-versa). That application is coming with sources and uses lame API as well (as far as I remember ).
Regards,
Ruslan
|
|
|
|
|
Thank you for this contribution.
I have a question:
Is it possible to detect silence?
Thanks again,
Where there is a WISH, there is a WILL.
|
|
|
|
|
Hi,
Yes it is possible, though I have studied this subject thoroughly. I was googling couple of months ago regarding this and find couple of useful articles, but nothing more. You may do the same, however, I still have one issue with this; since record is from soundcard's waveOut it's not quite clear how to determine if silence is due to music switch or just a silence as a part of the music's composition.
Regards,
Ruslan
|
|
|
|
|
Thank you again Ruslan.
I spent 2/3 of the night surfing on the web to study this matter and just find that your are right.
I'll have to personalize your code so that the file can be written chunk by chunk.
A way for me to be able to submit my different pieces to a commercial application that accept a couple of parameters to cut blanks: e.g. cut all records of least than 2DB during 3 min.
Regards,
Gaby.
Where there is a WISH, there is a WILL.
|
|
|
|
|
Is there any method to select default Mixer(checked) of Windows?
|
|
|
|
|
Hi,
Probably you mean identifying the default mixer device. If so, check the registry for:
HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Sound Mapper\Playback
HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Sound Mapper\Record
I am not sure this is the only way though.
Regards,
Ruslan
|
|
|
|
|