*/}}
ソースを参照

Audio capturing

YimingWu 4 ヶ月 前
コミット
0691937f59
2 ファイル変更41 行追加13 行削除
  1. 36 12
      la_audio.c
  2. 5 1
      la_interface.h

+ 36 - 12
la_audio.c

@@ -78,14 +78,20 @@ laPropContainer* LA_PC_IDN_SYNTH_TRIGGER;
 #define SAMPLE_RATE (MAIN.Audio->AudioSampleRate)
 
 void IDN_InputInit(laSynthNodeInput* n, int NoCreate){
-    INITPACKET(n->rTime); INITPACKET(n->rTrigger);
-    if(NoCreate){ return; }
+    INITPACKET(n->rTime); INITPACKET(n->rTrigger); //INITPACKET(n->rSamplesL); INITPACKET(n->rSamplesR);
+    if(NoCreate){
+        if(!n->OutL) n->OutL=laCreateOutSocket(n,"L",LA_PROP_FLOAT|LA_PROP_ARRAY);
+        if(!n->OutR) n->OutR=laCreateOutSocket(n,"R",LA_PROP_FLOAT|LA_PROP_ARRAY);
+        return;
+    }
     n->OutTime=laCreateOutSocket(n,"TIME",LA_PROP_FLOAT|LA_PROP_ARRAY);
     n->OutTrigger=laCreateOutSocket(n,"TRIGGER",LA_PROP_FLOAT|LA_PROP_ARRAY);
     strSafeSet(&n->Base.Name,"Input");
 }
 void IDN_InputDestroy(laSynthNodeInput* n){
-    laDestroyOutSocket(n->OutTime); laDestroyOutSocket(n->OutTrigger); strSafeDestroy(&n->Base.Name); memFree(n->rTime); memFree(n->rTrigger);
+    laDestroyOutSocket(n->OutTime); laDestroyOutSocket(n->OutTrigger);
+    laDestroyOutSocket(n->OutL); laDestroyOutSocket(n->OutR); strSafeDestroy(&n->Base.Name);
+    memFree(n->rTime); memFree(n->rTrigger); memFree(n->rSamplesL); memFree(n->rSamplesL);
 }
 int IDN_InputVisit(laSynthNodeInput* n, laNodeVisitInfo* vi){
     LA_GUARD_THIS_NODE(n,vi);
@@ -101,6 +107,7 @@ int IDN_InputEval(laSynthNodeInput* n){
     }
     if(ss->EvalSamples==0){ n->rTrigger[0] = 10; }else{ n->rTrigger[0]=0; }
     n->OutTime->Data=n->rTime; n->OutTrigger->Data=n->rTrigger; n->OutTime->ArrLen=LA_SYNTH_PLEN; n->OutTrigger->ArrLen=LA_SYNTH_PLEN;
+    n->OutL->Data=MAIN.Audio->InputSamples; n->OutR->Data=MAIN.Audio->InputSamples; n->OutL->ArrLen=LA_SYNTH_PLEN; n->OutR->ArrLen=LA_SYNTH_PLEN;
     return 1;
 }
 void IDN_InputCopy(laSynthNodeInput* new, laSynthNodeInput* old, int DoRematch){
@@ -112,7 +119,13 @@ void laui_InputNode(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn
     LA_BASE_NODE_HEADER(uil,c,This);
 
     laUiItem* b=laBeginRow(uil,c,0,0);
-    laUiItem* ui=laShowLabel(uil,c,"Synth",0,0); ui->Expand=1; ui->Flags|=LA_TEXT_ALIGN_RIGHT;
+    laUiItem* ui=laShowLabel(uil,c,"Capture",0,0); ui->Expand=1; ui->Flags|=LA_TEXT_ALIGN_RIGHT;
+    laShowNodeSocket(uil,c,This,"out_l",0)->Flags|=LA_UI_SOCKET_LABEL_E;
+    laShowNodeSocket(uil,c,This,"out_r",0)->Flags|=LA_UI_SOCKET_LABEL_E;
+    laEndRow(uil,b);
+
+    b=laBeginRow(uil,c,0,0);
+    ui=laShowLabel(uil,c,"Synth",0,0); ui->Expand=1; ui->Flags|=LA_TEXT_ALIGN_RIGHT;
     laShowNodeSocket(uil,c,This,"out_time",0)->Flags|=LA_UI_SOCKET_LABEL_E;
     laShowNodeSocket(uil,c,This,"out_trigger",0)->Flags|=LA_UI_SOCKET_LABEL_E;
     laEndRow(uil,b);
@@ -794,7 +807,7 @@ int laEvalSingleSynth(laSynth* ss){
 }
 int laEvalSynthGraphs(){
     laSynth* ss; int any=0;
-    memset(MAIN.Audio->AudioSamples,0,sizeof(real)*LA_SYNTH_PLEN);
+    memset(MAIN.Audio->OutputSamples,0,sizeof(real)*LA_SYNTH_PLEN);
     for(laAudioChannel* ac=MAIN.Audio->Channels.pFirst;ac;ac=ac->Item.pNext){
         memset(ac->Samples,0,sizeof(real)*LA_SYNTH_PLEN);
     }
@@ -805,26 +818,29 @@ int laEvalSynthGraphs(){
 
     for(laAudioChannel* ac=MAIN.Audio->Channels.pFirst;ac;ac=ac->Item.pNext){
         for(int i=0;i<LA_SYNTH_PLEN;i++){
-            MAIN.Audio->AudioSamples[i] += ac->Samples[i]*(ac->Volume/10);
+            MAIN.Audio->OutputSamples[i] += ac->Samples[i]*(ac->Volume/10);
         }
     }
     return any;
 }
 
 void laaudio_DataCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount){
-    float* out=pOutput; int Paused; int any=0;
+    float* out=pOutput,*in=pInput; int Paused; int any=0;
     laSpinLock(&MAIN.Audio->AudioStatusLock);
     Paused = MAIN.Audio->Paused;
     laSpinUnlock(&MAIN.Audio->AudioStatusLock);
     
-    if(Paused){ memset(out,0,sizeof(float)*LA_SYNTH_PLEN); return; }
+    if(Paused){ memset(out,0,sizeof(float)*LA_SYNTH_PLEN);
+        memset(MAIN.Audio->InputSamples,0,sizeof(float)*LA_SYNTH_PLEN); return;
+    }
     
     for(int i=0;i<frameCount;i++){
         if(MAIN.Audio->NextAudioSample>=LA_SYNTH_PLEN){
             MAIN.Audio->NextAudioSample=0;
             if(laEvalSynthGraphs()){ any=1; }
         }
-        out[i]=MAIN.Audio->AudioSamples[MAIN.Audio->NextAudioSample]/10;
+        out[i]=MAIN.Audio->OutputSamples[MAIN.Audio->NextAudioSample]/10;
+        MAIN.Audio->InputSamples[MAIN.Audio->NextAudioSample] = in[i] * 10;
         MAIN.Audio->NextAudioSample++;
     }
 }
@@ -836,8 +852,11 @@ void la_SelectAudioDevice(laAudioDevice* ad){
     ma_device_uninit(&MAIN.Audio->AudioDevice);
     if(!ad) return;
     int SampleRate=48000;
-    ma_device_config config = ma_device_config_init(ma_device_type_playback);
-    config.playback.pDeviceID= 0;
+    ma_device_config config = ma_device_config_init(ma_device_type_duplex);
+    config.capture.pDeviceID = ad->MiniAudioID;
+    config.capture.format    = ma_format_f32;
+    config.capture.channels  = 1;
+    config.playback.pDeviceID= ad->MiniAudioID;
     config.playback.format   = ma_format_f32;
     config.playback.channels = 1;
     config.sampleRate        = SampleRate;
@@ -881,11 +900,14 @@ void laInitMiniAudio(){
     laRefreshAudioDevices();
 
     laSpinInit(&MAIN.Audio->AudioStatusLock);
-    INITPACKET(MAIN.Audio->AudioSamples);
+    INITPACKET(MAIN.Audio->InputSamples);
+    INITPACKET(MAIN.Audio->OutputSamples);
 
     la_SelectAudioDevice(MAIN.Audio->AudioDevices.pFirst);
 }
 void laDeinitAudio(){
+    memFree(MAIN.Audio->InputSamples);
+    memFree(MAIN.Audio->OutputSamples);
     laSpinDestroy(&MAIN.Audio->AudioStatusLock);
     ma_device_stop(&MAIN.Audio->AudioDevice);
     ma_device_uninit(&MAIN.Audio->AudioDevice);
@@ -1258,6 +1280,8 @@ void laInitAudio(){
     laAddSubGroup(pc,"base","Base","Base node","la_base_node",0,0,0,0,0,0,0,0,0,0,0,LA_UDF_LOCAL);
     laAddSubGroup(pc,"out_time", "Out Time","Time output","la_out_socket",0,0,0,offsetof(laSynthNodeInput,OutTime),0,0,0,0,0,0,0,LA_UDF_SINGLE);
     laAddSubGroup(pc,"out_trigger", "Out Trigger","Trigger output","la_out_socket",0,0,0,offsetof(laSynthNodeInput,OutTrigger),0,0,0,0,0,0,0,LA_UDF_SINGLE);
+    laAddSubGroup(pc,"out_l", "Out Left","Capture left","la_out_socket",0,0,0,offsetof(laSynthNodeInput,OutL),0,0,0,0,0,0,0,LA_UDF_SINGLE);
+    laAddSubGroup(pc,"out_r", "Out Right","Capture right","la_out_socket",0,0,0,offsetof(laSynthNodeInput,OutR),0,0,0,0,0,0,0,LA_UDF_SINGLE);
     
     pc=laAddPropertyContainer("la_node_synth_pulse", "Synth Pulse Node", "Pulse generate node for synth",0,laui_PulseNode,sizeof(laSynthNodePulse),lapost_Node,0,1);
     LA_PC_IDN_PULSE=pc; laPropContainerExtraFunctions(pc,0,0,0,0,laui_DefaultNodeOperationsPropUiDefine);

+ 5 - 1
la_interface.h

@@ -1905,8 +1905,12 @@ STRUCTURE(laSynthNodeInput){
     laBaseNode Base;
     laNodeOutSocket* OutTime;
     laNodeOutSocket* OutTrigger;
+    laNodeOutSocket* OutL;
+    laNodeOutSocket* OutR;
     real* rTime;
     real* rTrigger;
+    real* rSamplesL;
+    real* rSamplesR;
 };
 
 STRUCTURE(laSynthNodePulse){
@@ -2041,7 +2045,7 @@ STRUCTURE(laAudio){
     laListHandle AudioDevices;
     laSynth* AudioEvalSynth;
     real AudioFrameInterval;
-    real* AudioSamples; int NextAudioSample,AudioSampleRate;
+    real* InputSamples,*OutputSamples; int NextAudioSample,AudioSampleRate;//,NextInputSample;
 };