40 lines
1.9 KiB
C
40 lines
1.9 KiB
C
|
|
/* Repeatable internal-device listening material; never opens audio hardware. */
|
||
|
|
#include "xtc/xtc_plugin.h"
|
||
|
|
#include "xtc/xtc_audio.h"
|
||
|
|
#include "xtc/xtc_midi.h"
|
||
|
|
#include <stdio.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
static xtc_result preview(const char *prefix, unsigned int id)
|
||
|
|
{
|
||
|
|
xtc_plugin_spec spec; xtc_plugin *plugin=NULL;xtc_recorder *recorder=NULL;
|
||
|
|
char path[1024];size_t block;xtc_result result;
|
||
|
|
int n=snprintf(path,sizeof(path),"%s-%u.wav",prefix,id);
|
||
|
|
if(n<0 || (size_t)n>=sizeof(path))return XTC_ERR_CAPACITY;
|
||
|
|
result=xtc_plugin_probe(XTC_BUILTIN_PATH,id,48000,&spec);
|
||
|
|
if(result==XTC_OK)result=xtc_plugin_create(&spec,48000,256,&plugin);
|
||
|
|
if(result==XTC_OK)result=xtc_recorder_create_replace(path,48000,256,1,&recorder);
|
||
|
|
for(block=0;result==XTC_OK && block<1125;++block) {
|
||
|
|
float input[256]={0},output[256];xtc_midi_event event={0,XTC_MIDI_NOTE_ON,0,60,100};
|
||
|
|
if(id<2) {
|
||
|
|
size_t count=0;
|
||
|
|
if(block==0 || block==94 || block==188) {event.pitch=block==0 ? 48U : block==94 ? 60U : 67U;count=1;}
|
||
|
|
if(block==282) {event.type=XTC_MIDI_CONTROL;event.pitch=123;event.velocity=0;count=1;}
|
||
|
|
result=xtc_plugin_process_midi(plugin,&event,count,output,256);
|
||
|
|
} else {
|
||
|
|
if(block==0 || block==94) input[0]=.5f;
|
||
|
|
result=xtc_plugin_process(plugin,input,output,256);
|
||
|
|
}
|
||
|
|
if(result==XTC_OK) {xtc_recorder_push(recorder,output,256);result=xtc_recorder_drain(recorder);}
|
||
|
|
}
|
||
|
|
if(result==XTC_OK)result=xtc_recorder_finish(recorder);
|
||
|
|
xtc_recorder_destroy(recorder);xtc_plugin_destroy(plugin);
|
||
|
|
if(result==XTC_OK)printf("Wrote %s\n",path);
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
int main(int argc,char **argv)
|
||
|
|
{
|
||
|
|
unsigned int id;
|
||
|
|
if(argc!=2) {fprintf(stderr,"Usage: %s OUTPUT_PREFIX\n",argv[0]);return EXIT_FAILURE;}
|
||
|
|
for(id=0;id<4;++id) if(preview(argv[1],id)!=XTC_OK)return EXIT_FAILURE;
|
||
|
|
return EXIT_SUCCESS;
|
||
|
|
}
|