int main() { xmp_context ctx; struct xmp_frame_info fi; int i, j; FILE *t = fopen("test.tmp", "wb+"); ctx = xmp_create_context(); xmp_load_module(ctx, "../tests/3d.mod"); xmp_start_player(ctx, 44100, 0); for (i=0;i<300;i++) { xmp_play_frame(ctx); xmp_get_frame_info(ctx, &fi); for (j=0;j<fi.buffer_size;j++) { fputc(((char *)fi.buffer)[j], t); } } printf("Dumped sound to `test.tmp`\n"); xmp_end_player(ctx); xmp_release_module(ctx); xmp_free_context(ctx); fclose(t); printf("Start playing...\n"); system("aplay test.tmp --rate=44100 -f cd"); printf("Deleting file...\n"); unlink("test.tmp"); return 0; }
int main(int argc, char **argv) { xmp_context ctx; struct xmp_module_info mi; struct xmp_frame_info fi; int i; ctx = xmp_create_context(); if (sdl_init(ctx) < 0) { fprintf(stderr, "%s: can't initialize sound\n", argv[0]); exit(1); } for (i = 1; i < argc; i++) { if (xmp_load_module(ctx, argv[i]) < 0) { fprintf(stderr, "%s: error loading %s\n", argv[0], argv[i]); continue; } if (xmp_start_player(ctx, 44100, 0) == 0) { /* Show module data */ xmp_get_module_info(ctx, &mi); printf("%s (%s)\n", mi.mod->name, mi.mod->type); /* Play module */ playing = 1; SDL_PauseAudio(0); while (playing) { SDL_Delay(10); xmp_get_frame_info(ctx, &fi); printf("%3d/%3d %3d/%3d\r", fi.pos, mi.mod->len, fi.row, fi.num_rows); fflush(stdout); } xmp_end_player(ctx); } xmp_release_module(ctx); printf("\n"); } xmp_free_context(ctx); sdl_deinit(); return 0; }
static void check_arpeggio_okt5(xmp_context opaque, int note, int val, int spd) { struct xmp_frame_info info; int i; int a2 = val & 0x0f; int arp[20]; char error[60]; for (i = 0; i < 12; ) { arp[i++] = note_to_period(note + a2); arp[i++] = note_to_period(note + a2); arp[i++] = note_to_period(note); } for (i = 0; i < spd; i++) { xmp_play_frame(opaque); xmp_get_frame_info(opaque, &info); snprintf(error, 60, "Oktalyzer arp5 0x%02x error", val); fail_unless(PERIOD == arp[i], error); } }
int main(int argc, char **argv) { xmp_context c; struct xmp_frame_info mi; FILE *f; /* The output raw file */ f = fopen("out.raw", "wb"); if (f == NULL) { fprintf(stderr, "can't open output file\n"); exit(EXIT_FAILURE); } /* Create the player context */ c = xmp_create_context(); /* Load our module */ if (xmp_load_module(c, argv[1]) != 0) { fprintf(stderr, "can't load module\n"); exit(EXIT_FAILURE); } /* Play the module */ xmp_start_player(c, 44100, 0); while (xmp_play_frame(c) == 0) { xmp_get_frame_info(c, &mi); if (mi.loop_count > 0) /* exit before looping */ break; fwrite(mi.buffer, mi.buffer_size, 1, stdout); /* write audio data */ } xmp_end_player(c); xmp_release_module(c); /* unload module */ xmp_free_context(c); /* destroy the player context */ fclose(f); exit(EXIT_SUCCESS); }
int32 USoundModWave::GeneratePCMData(uint8* PCMData, const int32 SamplesNeeded) { SCOPE_CYCLE_COUNTER(STAT_SoundModGeneratePCMData); int32 BytesGenerated = Super::GeneratePCMData(PCMData, SamplesNeeded); int32 BytesDesired = (SamplesNeeded * sizeof(int16)) - BytesGenerated; if (BytesDesired > 0) { while (xmp_play_frame(xmpContext) == 0) { xmp_frame_info xmpFrameInfo; xmp_get_frame_info(xmpContext, &xmpFrameInfo); const int32 BytesToCopy = FMath::Min<int32>(xmpFrameInfo.buffer_size, BytesDesired); if (BytesToCopy > 0) { FMemory::Memcpy((void*)(PCMData + BytesGenerated), xmpFrameInfo.buffer, BytesToCopy); BytesDesired -= BytesToCopy; BytesGenerated += BytesToCopy; if (BytesDesired == 0) { if (BytesToCopy != xmpFrameInfo.buffer_size) { QueueAudio((uint8*)xmpFrameInfo.buffer + BytesToCopy, xmpFrameInfo.buffer_size - BytesToCopy); } break; } } } } return BytesGenerated; }
static void _compare_mixer_data(char *mod, char *data, int loops, int ignore_rv) { xmp_context opaque; struct context_data *ctx; struct module_data *m; struct player_data *p; struct mixer_voice *vi; struct xmp_frame_info fi; int time, row, frame, chan, period, note, ins, vol, pan, pos0, cutoff; char line[200]; FILE *f; int i, voc, ret; f = fopen(data, "r"); fail_unless(f != NULL, "can't open data file"); opaque = xmp_create_context(); fail_unless(opaque != NULL, "can't create context"); ret = xmp_load_module(opaque, mod); fail_unless(ret == 0, "can't load module"); ctx = (struct context_data *)opaque; m = &ctx->m; p = &ctx->p; xmp_start_player(opaque, 44100, 0); xmp_set_player(opaque, XMP_PLAYER_MIX, 100); while (1) { xmp_play_frame(opaque); xmp_get_frame_info(opaque, &fi); if (fi.loop_count >= loops) break; for (i = 0; i < m->mod.chn; i++) { struct xmp_channel_info *ci = &fi.channel_info[i]; struct channel_data *xc = &p->xc_data[i]; int num; voc = map_channel(p, i); if (voc < 0 || TEST_NOTE(NOTE_SAMPLE_END)) continue; vi = &p->virt.voice_array[voc]; fgets(line, 200, f); num = sscanf(line, "%d %d %d %d %d %d %d %d %d %d %d", &time, &row, &frame, &chan, &period, ¬e, &ins, &vol, &pan, &pos0, &cutoff); fail_unless(fi.time == time, "time mismatch"); fail_unless(fi.row == row, "row mismatch"); fail_unless(fi.frame == frame, "frame mismatch"); fail_unless(i == chan, "channel mismatch"); fail_unless(ci->period == period, "period mismatch"); fail_unless(vi->note == note, "note mismatch"); fail_unless(vi->ins == ins, "instrument"); if (!ignore_rv) { fail_unless(vi->vol == vol, "volume mismatch"); fail_unless(vi->pan == pan, "pan mismatch"); } fail_unless(vi->pos0 == pos0, "position mismatch"); if (num >= 11) { fail_unless(vi->filter.cutoff == cutoff, "cutoff mismatch"); } } } fgets(line, 200, f); fail_unless(feof(f), "not end of data file"); xmp_end_player(opaque); xmp_release_module(opaque); xmp_free_context(opaque); }
event_t * fa_xmp_playfile(media_pipe_t *mp, FILE *f, char *errbuf, size_t errlen, int hold, const char *url, size_t size) { event_t *e = NULL; xmp_context ctx = xmp_create_context(); // struct xmp_module_info mi; struct xmp_frame_info fi; char *u = mystrdupa(url); mp->mp_audio.mq_stream = 0; mp_configure(mp, MP_CAN_PAUSE | MP_CAN_SEEK, MP_BUFFER_SHALLOW, 0, "tracks"); mp_become_primary(mp); if(xmp_load_modulef(ctx, f, u, size) >= 0) { if(xmp_start_player(ctx, 44100, 0) == 0) { media_buf_t *mb = NULL; media_queue_t *mq = &mp->mp_audio; while(1) { if(mb == NULL) { if(xmp_play_frame(ctx)) { e = event_create_type(EVENT_EOF); break; } xmp_get_frame_info(ctx, &fi); if(fi.loop_count > 0) { e = event_create_type(EVENT_EOF); break; } mb = media_buf_alloc_unlocked(mp, fi.buffer_size); mb->mb_data_type = MB_AUDIO; mb->mb_channels = 2; mb->mb_rate = 44100; mb->mb_pts = fi.time * 1000; mb->mb_drive_clock = 1; memcpy(mb->mb_data, fi.buffer, fi.buffer_size); mp_set_duration(mp, fi.total_time * 1000); } if((e = mb_enqueue_with_events(mp, mq, mb)) == NULL) { mb = NULL; /* Enqueue succeeded */ continue; } if(event_is_type(e, EVENT_PLAYQUEUE_JUMP)) { mp_flush(mp, 0); break; } else if(event_is_action(e, ACTION_SKIP_BACKWARD) || event_is_action(e, ACTION_SKIP_FORWARD) || event_is_action(e, ACTION_STOP)) { mp_flush(mp, 0); break; } event_release(e); } xmp_end_player(ctx); } else { snprintf(errbuf, errlen, "XMP failed to start"); } } else { snprintf(errbuf, errlen, "XMP Loading error"); } // prop_ref_dec(dur); xmp_free_context(ctx); return e; }
int main(int argc, char **argv) { xmp_context ctx; struct xmp_module_info mi; struct xmp_frame_info fi; int row, pos, i; if (sound_init(44100, 2) < 0) { fprintf(stderr, "%s: can't initialize sound\n", argv[0]); exit(1); } ctx = xmp_create_context(); for (i = 1; i < argc; i++) { if (xmp_load_module(ctx, argv[i]) < 0) { fprintf(stderr, "%s: error loading %s\n", argv[0], argv[i]); continue; } if (xmp_start_player(ctx, 44100, 0) == 0) { /* Show module data */ xmp_get_module_info(ctx, &mi); printf("%s (%s)\n", mi.mod->name, mi.mod->type); /* Play module */ row = pos = -1; while (xmp_play_frame(ctx) == 0) { xmp_get_frame_info(ctx, &fi); if (fi.loop_count > 0) break; sound_play(fi.buffer, fi.buffer_size); if (fi.pos != pos) { printf("\n%02x:%02x\n", fi.pos, fi.pattern); pos = fi.pos; row = -1; } if (fi.row != row) { display_data(&mi, &fi); row = fi.row; } } xmp_end_player(ctx); } xmp_release_module(ctx); printf("\n"); } xmp_free_context(ctx); sound_deinit(); return 0; }