struct PEventQueue *GetPEQelement(void) { struct PEventQueue *temp=peqroot; if(temp==NULL) { // This should REALLY not happen. //temp=GC_malloc(sizeof(struct PEventQueue)); temp=V_malloc(sizeof(struct PEventQueue)); if(temp==NULL) { RT_message("Error. Out of memory on a very bad place. Now probably crashing.\n"); } } else { peqroot=NextPEventQueue(temp); } ++num_elements_used; //printf(" +NUM ELEMENTS: %d\n",num_elements_used); if(num_elements_used > INITIAL_NUM_ELEMENTS-SAFETY_BUFFER) { RT_message("<p>Stopping player.</p><p>We are at risk of running out of memory for the player.</p>This is a bug in Radium, and is not supposed to happen.</p><p>Please report this bug.</p>"); RT_request_to_stop_playing(); } return temp; }
static void RT_process(SoundPlugin *plugin, int64_t time, int num_frames, float **inputs, float **outputs){ Data *data = (Data*)plugin->data; #if 0 for(int ch=0; ch<data->num_output_channels ; ch++) memset(outputs[ch], 0, sizeof(float)*num_frames); return; #endif // 1. Process audio AudioPluginInstance *instance = data->audio_instance; AudioSampleBuffer &buffer = data->buffer; for(int ch=0; ch<data->num_input_channels ; ch++) memcpy(buffer.getWritePointer(ch), inputs[ch], sizeof(float)*num_frames); int pos = CRASHREPORTER_set_plugin_name(plugin->type->name);{ instance->processBlock(buffer, data->midi_buffer); }CRASHREPORTER_unset_plugin_name(pos); for(int ch=0; ch<data->num_output_channels ; ch++) memcpy(outputs[ch], buffer.getReadPointer(ch), sizeof(float)*num_frames); // 2. Send out midi (untested, need plugin to test with) volatile struct Patch *patch = plugin->patch; if (patch!=NULL) { MidiBuffer::Iterator iterator(data->midi_buffer); MidiMessage message; int samplePosition; while(iterator.getNextEvent(message, samplePosition)){ #ifndef RELEASE if (samplePosition >= num_frames || samplePosition < 0) RT_message("The instrument named \"%s\" of type %s/%s\n" "returned illegal sample position: %d", patch==NULL?"<no name>":patch->name, plugin->type->type_name, plugin->type->name, samplePosition ); #endif // Make sure samplePosition has a legal value if (samplePosition >= num_frames) samplePosition = num_frames-1; if (samplePosition < 0) samplePosition = 0; int64_t delta_time = PLAYER_get_block_delta_time(pc->start_time+samplePosition); int64_t radium_time = pc->start_time + delta_time; RT_MIDI_send_msg_to_patch_receivers((struct Patch*)patch, message, radium_time); } } }
int MIDI_msg_len(uint32_t msg){ int byte1 = MIDI_msg_byte1(msg); R_ASSERT(byte1!=0xf0); R_ASSERT(byte1!=0xf7); if (byte1<0x80 || byte1>0xff){ RT_message("Illegal msg: %x",msg); return 0; } return MidiMessage::getMessageLengthFromFirstByte(byte1); }
int RT_MIDI_send_msg_to_patch(struct Patch *patch, void *data, int data_size, int64_t seq_time){ int num_bytes_used; R_ASSERT(data_size>0); { uint8_t *d=(uint8_t*)data; if (d[0] < 0x80) { RT_message("Illegal value in first byte of MIDI message: %d\n",d[0]); return 0; } } MidiMessage message(data, data_size, num_bytes_used, 0); RT_MIDI_send_msg_to_patch(patch, message, seq_time); return num_bytes_used; }