How I managed to use the microphone in Panda3D

I recently spent some time trying to use a microphone as a sound input in Panda3D under Windows.
Several old posts described this possibility, but no detailed implementation was given.

So, just for those of you interested, this is how I managed to make it work.

This is a quick (and dirty?) practical approach

  1. grab MicrophoneAudioDS.cxx file from Panda3D source
    edit it and merely make public the call to open()
// private:
  virtual PT(MovieAudioCursor) open();
  1. in your c++ program add the following includes
#include "audioManager.h"
#include "microphoneAudio.h"
#include "microphoneAudioDS.cxx"
#include "userDataAudio.h"
  1. define microphone access
PT(MicrophoneAudio) mic;		// micro 
PT(MicrophoneAudioCursorDS) micCursor;// audio cursor for micro stream
PT(UserDataAudio) micAudio;	// micro  channel 2 , 44100hz
  1. then explore all possible microphone input
MicrophoneAudioDS::find_all_microphones_ds();		// check microphone options
int num_options = MicrophoneAudioDS::get_num_options();
for (int m=0; m<num_options; m++) 
   cout << "mike option "<< m << " "<<MicrophoneAudioDS::get_option(m)->get_name()<< "\n";
mic        = MicrophoneAudioDS::get_option(2); // channel 2 , 44100hz
micCursor = DCAST(MicrophoneAudioCursorDS,mic->open()); 

then you can get audio samples and play them with Audio Manager

That is not how you should use it! You shouldn’t mess with MicrophoneAudioDS at all, or include any cxx files. Use the static methods on MicrophoneAudio.

Agreed in the principle, but when I originally tried:

#include "audioManager.h"
#include "microphoneAudio.h"
#include "userDataAudio.h"

PT(MicrophoneAudio) mic;     // micro
PT(MicrophoneAudioCursor) micCursor;// audio cursor for micro stream
PT(UserDataAudio) micAudio;  // micro  channel 2, 44100hz

MicrophoneAudio::find_all_microphones();      // check microphone options
int num_options = MicrophoneAudio::get_num_options();
for (int m=0; m<num_options; m++)
   cout << "mike option "<< m << " "<<MicrophoneAudio::get_option(m)->get_name()<< "\n";
mic       = MicrophoneAudio::get_option(2); // channel 2 , 44100hz
micCursor = DCAST(MicrophoneAudioCursor,mic->open());

The num_options ended up being reported as 0!!!

This is the reason why I tried this (horrible) hack !

Having the same issue here; Was the underlying problem ever identified and resolved? Also, thank you for posting your workaround for others to use as well. :slight_smile: