user2200585
user2200585

Reputation: 283

record sound from speakers or stereo mix

I've searched some examples and found this:

var
  op: TMCI_Open_Parms;
  rp: TMCI_Record_Parms;
  sp: TMCI_SaveParms;
begin

  // Open
  op.lpstrDeviceType := 'waveaudio';
  op.lpstrElementName := '';
  if mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT or MCI_OPEN_TYPE, cardinal(@op)) <> 0 then
    raise Exception.Create('MCI error');

  try

    // Record
    rp.dwFrom := 0;
    rp.dwTo := 10000;
    rp.dwCallback := 0;
    if mciSendCommand(op.wDeviceID, MCI_RECORD, MCI_TO or MCI_WAIT, cardinal(@rp)) <> 0 then
      raise Exception.Create('MCI error. No microphone connected to the computer?');

    // Save
    sp.lpfilename := PChar(ExtractFilePath(Application.ExeName) + 'test.wav');
    if mciSendCommand(op.wDeviceID, MCI_SAVE, MCI_SAVE_FILE or MCI_WAIT, cardinal(@sp)) <> 0 then
      raise Exception.Create('MCI error');

  finally
    mciSendCommand(op.wDeviceID, MCI_CLOSE, 0, 0);
  end;

it records only microphone, can I record speakers and microphone simultaniously? or separately?

Upvotes: 3

Views: 1780

Answers (1)

SilverWarior
SilverWarior

Reputation: 8386

The ability to do this largely depends on which Windows version are you using.

If you are still using Windows XP you might have "Software mix" or "Stereo out" recoding channels available.

But if you are using Windows Vista or newer these channels are no longer available. Well not without the use of some unofficial sound card drivers.

The main reason for this is that ability to record entire sound card output was invalidating any digital copyright protection for audio files.

So in order to achieve what you need you will have to find some custom sound library which would be able to directly play the music from Youtube mix your microphone with hat and output (record) that into some file.

I think you might be able to achieve this with Bass sound library (http://www.un4seen.com/) but I'm not sure.

Another option would be to directly connect Wave Out line into Line in port using cable and then record contents from Line in instead from microphone. Also make sure to allow your microphone voice to be played over speakers (disabled by default on most sound cards for avoiding possible sound echo).

EDIT: After taking a look at program named Audacity I found out that recording of your computers sound output only works if you chose WASAPI as sound interface.

Looking further about the WASAPI it seems this is new audio interface that has been introduced with Windows Vista. Now I must admit that I haven't known about this before.

So it seems that answer would lie in using WASAPI instead of old MME audio interface.

Quick search on Google does indicate that some people already managed to use WASAPI from Delphi.

Now since I don't have any experience with this new sound API I'm afraid that I can't be of more help to you than recommending you to learn about WASAPI and find some examples for it.

EDIT2: Managed to find a small example of using WASAPI interface in Delphi for Loopback recording. You can get it here:

http://4coder.org/delphi-source-code/547/

Also found a thread on DelphiPraxis about someone making a specially purposed unit for loopback recording with WASAPI in Delphi but since I'm not a member of DelphiPraxis I can't download it and test it.

http://www.delphipraxis.net/183977-wasapi-loopback-audio-capturing.html

Upvotes: 6

Related Questions