From 1473512180a0080ef526b6acdbb3d8ddedb1b463 Mon Sep 17 00:00:00 2001 From: Sonicadvance1 Date: Tue, 4 Nov 2008 09:05:10 +0000 Subject: [PATCH] Tons more Microphone work, due to me sucking, it doesn't work yet though. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1066 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/HW/EXI_DeviceMic.cpp | 117 ++++++++++++++++++---- Source/Core/Core/Src/HW/EXI_DeviceMic.h | 6 -- 2 files changed, 98 insertions(+), 25 deletions(-) diff --git a/Source/Core/Core/Src/HW/EXI_DeviceMic.cpp b/Source/Core/Core/Src/HW/EXI_DeviceMic.cpp index 6a30c8b719..f0f8e18a57 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceMic.cpp +++ b/Source/Core/Core/Src/HW/EXI_DeviceMic.cpp @@ -23,17 +23,75 @@ #include "EXI_Device.h" #include "EXI_DeviceMic.h" + + bool MicButton; + bool IsOpen; +// Doing it this way since it's Linux only atm due to portaudio, even though the lib is crossplatform +// I had to include libs in the DolphinWX Sconscript file which I thought was BS. +// So I'm committing with all the code ifdeff'ed out +#if 1 +void SetMic(bool Value) +{} +bool GetMic() +{return false;} +CEXIMic::CEXIMic(int _Index){} +CEXIMic::~CEXIMic(){} +bool CEXIMic::IsPresent() {return false;} +void CEXIMic::SetCS(int cs){} +void CEXIMic::Update(){} +void CEXIMic::TransferByte(u8 &byte){} +bool CEXIMic::IsInterruptSet(){return false;} +#else + +#include +#include + + unsigned char InputData[128*44100]; // Max Data is 128 samples at 44100 + PaStream *stream; + PaError err; + unsigned short SFreq; + unsigned short SNum; + unsigned int Sample; + bool m_bInterruptSet; + bool Sampling; -bool MicButton = false; void SetMic(bool Value) { - MicButton = Value; + if(Value != MicButton) + { + MicButton = Value; + printf("Mic is set to %s\n", MicButton ? "true" : "false"); + if(Sampling) + { + if(MicButton) + Pa_StartStream( stream ); + else + Pa_StopStream( stream ); + } + } } bool GetMic() { return MicButton; } +static unsigned int k = 0; +int patestCallback( const void *inputBuffer, void *outputBuffer, + unsigned long framesPerBuffer, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ) +{ + unsigned char *data = (unsigned char*)inputBuffer; + unsigned int i; + + for( i=0; i= SNum) - { - Sample = 0; - m_bInterruptSet = true; - } - else - Sample++; + Status.U16 &= ~(1 << 7); } byte = (u8)(Status.U16 >> (24-(((m_uPosition-2) & 3) * 8))); @@ -165,7 +221,8 @@ void CEXIMic::TransferByte(u8 &byte) else { Sampling = false; - m_bInterruptSet = false; + // Only set to false once we have run out of Data? + //m_bInterruptSet = false; } if(!(Status.U16 >> 11) & 1) if((Status.U16 >> 12) & 1 ) @@ -186,17 +243,38 @@ void CEXIMic::TransferByte(u8 &byte) for(int a = 0;a < 16;a++) printf("%d ", (Status.U16 >> a) & 1); printf("\n"); + if(!IsOpen) + { + // Open Our PortAudio Stream + err = Pa_OpenDefaultStream( &stream, + 1, + 0, + paUInt8 , + SFreq, + SNum, + patestCallback, + NULL); + if( err != paNoError ) + printf("error %s\n", Pa_GetErrorText (err)); + IsOpen = true; + } } } break; case cmdGetBuffer: + static unsigned long At = 0; printf("POS %d\n", m_uPosition); // Are we not able to return all the data then? // I think if we set the Interrupt to false, it reads another 64 // Will Look in to it. - if(m_uPosition == SNum / 2) // It's 16bit Audio, so we divide by two - ;//m_bInterruptSet = false; - byte = rand() % 0xFF; + // Set to False here? Prevents lock ups maybe? + if(At >= SNum){ + At = 0; + k = 0; + m_bInterruptSet = false; + } + byte = InputData[At]; + At++; break; default: printf("Don't know command %x in Byte transfer\n", command); @@ -205,3 +283,4 @@ void CEXIMic::TransferByte(u8 &byte) } m_uPosition++; } +#endif diff --git a/Source/Core/Core/Src/HW/EXI_DeviceMic.h b/Source/Core/Core/Src/HW/EXI_DeviceMic.h index b183b28333..d35c43c63c 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceMic.h +++ b/Source/Core/Core/Src/HW/EXI_DeviceMic.h @@ -18,7 +18,6 @@ #ifndef _EXI_DEVICEMIC_H #define _EXI_DEVICEMIC_H - class CEXIMic : public IEXIDevice { public: @@ -52,7 +51,6 @@ private: // STATE_TO_SAVE int interruptSwitch; - bool m_bInterruptSet; int command; union uStatus { @@ -63,10 +61,6 @@ private: u32 m_uPosition; u32 formatDelay; uStatus Status; - bool Sampling; - short SFreq; - short SNum; - int Sample; //! memory card parameters unsigned int ID;