Example #1
0
static int play(char *fn)
{
	char filename[MAX_PATH];
	int song;
	const ASAPInfo *info;
	int channels;
	int maxlatency;
	DWORD threadId;
	strcpy(playing_filename_with_song, fn);
	song = extractSongNumber(fn, filename);
	if (!loadModule(filename, module, &module_len))
		return -1;
	if (!ASAP_Load(asap, filename, module, module_len))
		return 1;
	info = ASAP_GetInfo(asap);
	if (song < 0)
		song = ASAPInfo_GetDefaultSong(info);
	duration = playSong(song);
	channels = ASAPInfo_GetChannels(info);
	maxlatency = mod.outMod->Open(ASAP_SAMPLE_RATE, channels, BITS_PER_SAMPLE, -1, -1);
	if (maxlatency < 0)
		return 1;
	mod.SetInfo(BITS_PER_SAMPLE, ASAP_SAMPLE_RATE / 1000, channels, 1);
	mod.SAVSAInit(maxlatency, ASAP_SAMPLE_RATE);
	// the order of VSASetInfo's arguments in in2.h is wrong!
	// http://forums.winamp.com/showthread.php?postid=1841035
	mod.VSASetInfo(ASAP_SAMPLE_RATE, channels);
	mod.outMod->SetVolume(-666);
	seek_needed = -1;
	thread_run = TRUE;
	thread_handle = CreateThread(NULL, 0, playThread, NULL, 0, &threadId);
	setPlayingSong(filename, song);
	return thread_handle != NULL ? 0 : 1;
}
Example #2
0
	void retag_set_info(t_uint32 p_subsong, const file_info &p_info, abort_callback &p_abort)
	{
		ASAPInfo *info = const_cast<ASAPInfo *>(ASAP_GetInfo(asap));
		ASAPInfo_SetAuthor(info, empty_if_null(p_info.meta_get("composer", 0)));
		ASAPInfo_SetTitle(info, empty_if_null(p_info.meta_get("title", 0)));
		ASAPInfo_SetDate(info, empty_if_null(p_info.meta_get("date", 0)));
	}
Example #3
0
int TrackCount(const char* strFile)
{
  void* file = XBMC->OpenFile(strFile, 0);
  if (!file)
    return 1;

  int len = XBMC->GetFileLength(file);
  uint8_t* data = new uint8_t[len];
  XBMC->ReadFile(file, data, len);
  XBMC->CloseFile(file);

  ASAP* asap = ASAP_New();

  // Now load the module
  if (!ASAP_Load(asap, strFile, data, len))
  {
    ASAP_Delete(asap);
    delete[] data;
    return 1;
  }
  delete[] data;

  const ASAPInfo* info = ASAP_GetInfo(asap);
  int result = ASAPInfo_GetSongs(info);
  ASAP_Delete(asap);

  return result;
}
Example #4
0
int playSong(int song)
{
	int duration = getSongDurationInternal(ASAP_GetInfo(asap), song, asap);
	ASAP_PlaySong(asap, song, duration); /* FIXME: check errors */
	ASAP_MutePokeyChannels(asap, mute_mask);
	return duration;
}
Example #5
0
static void asap_play_file(char *filename)
{
	const ASAPInfo *info;
	int song;
	int duration;
	char *title;
	if (asap == NULL)
		return;
	if (!asap_load_file(filename))
		return;
	if (!ASAP_Load(asap, filename, module, module_len))
		return;
	info = ASAP_GetInfo(asap);
	song = ASAPInfo_GetDefaultSong(info);
	duration = ASAPInfo_GetDuration(info, song);
	if (!ASAP_PlaySong(asap, song, duration))
		return;
	channels = ASAPInfo_GetChannels(info);
	if (!mod.output->open_audio(BITS_PER_SAMPLE == 8 ? FMT_U8 : FMT_S16_LE, ASAP_SAMPLE_RATE, channels))
		return;
	title = asap_get_title(filename, info);
	mod.set_info(title, duration, BITS_PER_SAMPLE * 1000, ASAP_SAMPLE_RATE, channels);
	g_free(title);
	seek_to = -1;
	thread_run = TRUE;
	generated_eof = FALSE;
	pthread_create(&thread_handle, NULL, asap_play_thread, NULL);
}
static int asap_decode(void *data, char *buf, int buf_len, struct sound_params *sound_params)
{
	ASAP_Decoder *d = (ASAP_Decoder *) data;
	sound_params->channels = ASAPInfo_GetChannels(ASAP_GetInfo(d->asap));
	sound_params->rate = ASAP_SAMPLE_RATE;
	sound_params->fmt = BITS_PER_SAMPLE == 8 ? SFMT_U8 : (SFMT_S16 | SFMT_LE);
	return ASAP_Generate(d->asap, (unsigned char *) buf, buf_len, BITS_PER_SAMPLE == 8 ? ASAPSampleFormat_U8 : ASAPSampleFormat_S16_L_E);
}
static void *asap_open(const char *uri)
{
	ASAP_Decoder *d = (ASAP_Decoder *) xmalloc(sizeof(ASAP_Decoder));
	if (!asap_load(d, uri) || !ASAP_PlaySong(d->asap, ASAPInfo_GetDefaultSong(ASAP_GetInfo(d->asap)), d->duration)) {
		asap_close(d);
		return NULL;
	}
	return d;
}
Example #8
0
	void retag_commit(abort_callback &p_abort)
	{
		m_file.release();
		filesystem::g_open(m_file, filename, filesystem::open_mode_write_new, p_abort);
		this->p_abort = &p_abort;
		ByteWriter bw = { this, static_write };
		if (!ASAPWriter_Write(filename, bw, ASAP_GetInfo(asap), module, module_len, FALSE))
			throw exception_io_unsupported_format();
	}
Example #9
0
	CInputDecoder * __cdecl Open(char *filename, int audioDataOffset)
	{
		BYTE module[ASAPInfo_MAX_MODULE_LENGTH];
		int module_len;
		if (!loadModule(filename, module, &module_len))
			return NULL;
		if (!ASAP_Load(asap, filename, module, module_len))
			return NULL;
		playSong(ASAPInfo_GetDefaultSong(ASAP_GetInfo(asap)));
		return new CASAPDecoder();
	}
Example #10
0
void* Init(const char* strFile, unsigned int filecache, int* channels,
           int* samplerate, int* bitspersample, int64_t* totaltime,
           int* bitrate, AEDataFormat* format, const AEChannel** channelinfo)
{
  int track=0;
  std::string toLoad(strFile);
  if (toLoad.find(".asapstream") != std::string::npos)
  {
    size_t iStart=toLoad.rfind('-') + 1;
    track = atoi(toLoad.substr(iStart, toLoad.size()-iStart-11).c_str());
    //  The directory we are in, is the file
    //  that contains the bitstream to play,
    //  so extract it
    size_t slash = toLoad.rfind('\\');
    if (slash == std::string::npos)
      slash = toLoad.rfind('/');
    toLoad = toLoad.substr(0, slash);
  }

  void* file = XBMC->OpenFile(toLoad.c_str(),0);
  if (!file)
    return NULL;

  int len = XBMC->GetFileLength(file);
  uint8_t* data = new uint8_t[len];
  XBMC->ReadFile(file, data, len);
  XBMC->CloseFile(file);

  ASAPContext* result = new ASAPContext;
  result->asap = ASAP_New();

  // Now load the module
  if (!ASAP_Load(result->asap, toLoad.c_str(), data, len))
  {
    delete[] data;
    delete result;
  }
  delete[] data;

  const ASAPInfo* info = ASAP_GetInfo(result->asap);

  *channels = ASAPInfo_GetChannels(info);
  *samplerate = 44100;
  *bitspersample = 16;
  *totaltime = ASAPInfo_GetDuration(info, track);
  *format = AE_FMT_S16NE;
  *channelinfo = NULL;
  *bitrate = 0;

  ASAP_PlaySong(result->asap, track, *totaltime);

  return result;
}
Example #11
0
	void get_info(t_uint32 p_subsong, file_info &p_info, abort_callback &p_abort)
	{
		int duration = get_song_duration(p_subsong, false);
		if (duration >= 0)
			p_info.set_length(duration / 1000.0);
		const ASAPInfo *info = ASAP_GetInfo(asap);
		p_info.info_set_int("channels", ASAPInfo_GetChannels(info));
		p_info.info_set_int("subsongs", ASAPInfo_GetSongs(info));
		meta_set(p_info, "composer", ASAPInfo_GetAuthor(info));
		meta_set(p_info, "title", ASAPInfo_GetTitle(info));
		meta_set(p_info, "date", ASAPInfo_GetDate(info));
	}
Example #12
0
	int get_song_duration(int song, bool play)
	{
		const ASAPInfo *info = ASAP_GetInfo(asap);
		int duration = ASAPInfo_GetDuration(info, song);
		if (duration < 0) {
			if (play)
				ASAP_DetectSilence(asap, silence_seconds);
			return 1000 * song_length;
		}
		if (play)
			ASAP_DetectSilence(asap, 0);
		if (play_loops && ASAPInfo_GetLoop(info, song))
			return 1000 * song_length;
		return duration;
	}
Example #13
0
	bool decode_run(audio_chunk &p_chunk, abort_callback &p_abort)
	{
		int channels = ASAPInfo_GetChannels(ASAP_GetInfo(asap));
		int buffered_bytes = BUFFERED_BLOCKS * channels * (BITS_PER_SAMPLE / 8);
		static BYTE buffer[BUFFERED_BLOCKS * 2 * (BITS_PER_SAMPLE / 8)];

		buffered_bytes = ASAP_Generate(asap, buffer, buffered_bytes,
			BITS_PER_SAMPLE == 8 ? ASAPSampleFormat_U8 : ASAPSampleFormat_S16_L_E);
		if (buffered_bytes == 0)
			return false;
		p_chunk.set_data_fixedpoint(buffer, buffered_bytes, ASAP_SAMPLE_RATE,
			channels, BITS_PER_SAMPLE,
			channels == 2 ? audio_chunk::channel_config_stereo : audio_chunk::channel_config_mono);
		return true;
	}
Example #14
0
static DWORD WINAPI playThread(LPVOID dummy)
{
	int channels = ASAPInfo_GetChannels(ASAP_GetInfo(asap));
	while (thread_run) {
		static BYTE buffer[BUFFERED_BLOCKS * 2 * (BITS_PER_SAMPLE / 8)
#if SUPPORT_EQUALIZER
			* 2
#endif
			];
		int buffered_bytes = BUFFERED_BLOCKS * channels * (BITS_PER_SAMPLE / 8);
		if (seek_needed >= 0) {
			mod.outMod->Flush(seek_needed);
			ASAP_Seek(asap, seek_needed);
			seek_needed = -1;
		}
		if (mod.outMod->CanWrite() >= buffered_bytes
#if SUPPORT_EQUALIZER
			<< mod.dsp_isactive()
#endif
		) {
			int t;
			buffered_bytes = ASAP_Generate(asap, buffer, buffered_bytes, BITS_PER_SAMPLE == 8 ? ASAPSampleFormat_U8 : ASAPSampleFormat_S16_L_E);
			if (buffered_bytes <= 0) {
				mod.outMod->CanWrite();
				if (!mod.outMod->IsPlaying()) {
					PostMessage(mod.hMainWindow, WM_WA_MPEG_EOF, 0, 0);
					return 0;
				}
				Sleep(10);
				continue;
			}
			t = mod.outMod->GetWrittenTime();
			mod.SAAddPCMData(buffer, channels, BITS_PER_SAMPLE, t);
			mod.VSAAddPCMData(buffer, channels, BITS_PER_SAMPLE, t);
#if SUPPORT_EQUALIZER
			t = buffered_bytes / (channels * (BITS_PER_SAMPLE / 8));
			t = mod.dsp_dosamples((short *) buffer, t, BITS_PER_SAMPLE, channels, ASAP_SAMPLE_RATE);
			t *= channels * (BITS_PER_SAMPLE / 8);
			mod.outMod->Write((char *) buffer, t);
#else
			mod.outMod->Write((char *) buffer, buffered_bytes);
#endif
		}
		else
			Sleep(20);
	}
	return 0;
}
static void asap_info(const char *file, struct file_tags *tags, const int tags_sel)
{
	ASAP_Decoder d;
	if (asap_load(&d, file)) {
		if ((tags_sel & TAGS_COMMENTS) != 0) {
			const ASAPInfo *info = ASAP_GetInfo(d.asap);
			tags->title = xstrdup(ASAPInfo_GetTitleOrFilename(info));
			tags->artist = xstrdup(ASAPInfo_GetAuthor(info));
			tags->filled |= TAGS_COMMENTS;
		}
		if ((tags_sel & TAGS_TIME) != 0) {
			tags->time = d.duration / 1000;
			tags->filled |= TAGS_TIME;
		}
	}
	ASAP_Delete(d.asap);
}
Example #16
0
bool ReadTag(const char* strFile, char* title, char* artist,
             int* length)
{
  int track=1;
  std::string toLoad(strFile);
  if (toLoad.find(".asapstream") != std::string::npos)
  {
    size_t iStart=toLoad.rfind('-') + 1;
    track = atoi(toLoad.substr(iStart, toLoad.size()-iStart-11).c_str());
    //  The directory we are in, is the file
    //  that contains the bitstream to play,
    //  so extract it
    size_t slash = toLoad.rfind('\\');
    if (slash == std::string::npos)
      slash = toLoad.rfind('/');
    toLoad = toLoad.substr(0, slash);
  }
  void* file = XBMC->OpenFile(toLoad.c_str(), 0);
  if (!file)
    return false;

  int len = XBMC->GetFileLength(file);
  uint8_t* data = new uint8_t[len];
  XBMC->ReadFile(file, data, len);
  XBMC->CloseFile(file);

  ASAP* asap = ASAP_New();

  // Now load the module
  if (!ASAP_Load(asap, strFile, data, len))
  {
    delete[] data;
    return false;
  }

  delete[] data;

  const ASAPInfo* info = ASAP_GetInfo(asap);
  strcpy(artist, ASAPInfo_GetAuthor(info));
  strcpy(title, ASAPInfo_GetTitleOrFilename(info));
  *length = ASAPInfo_GetDuration(info, track);

  return true;
}
static cibool asap_load(ASAP_Decoder *d, const char *filename)
{
	struct io_stream *s;
	ssize_t module_len;
	unsigned char *module;
	cibool ok;
	const ASAPInfo *info;
	int song;
	int duration;

	d->asap = NULL;
	decoder_error_init(&d->error);
	s = io_open(filename, 0);
	if (s == NULL) {
		decoder_error(&d->error, ERROR_FATAL, 0, "Can't open %s", filename);
		return FALSE;
	}
	module_len = io_file_size(s);
	module = (unsigned char *) xmalloc(module_len);
	module_len = io_read(s, module, module_len);
	io_close(s);

	d->asap = ASAP_New();
	if (d->asap == NULL) {
		decoder_error(&d->error, ERROR_FATAL, 0, "Out of memory");
		return FALSE;
	}

	ok = ASAP_Load(d->asap, filename, module, module_len);
	free(module);
	if (!ok) {
		decoder_error(&d->error, ERROR_FATAL, 0, "Unsupported file format");
		return FALSE;
	}
	info = ASAP_GetInfo(d->asap);
	song = ASAPInfo_GetDefaultSong(info);
	duration = ASAPInfo_GetDuration(info, song);
	if (duration < 0)
		duration = DEFAULT_SONG_LENGTH * 1000;
	d->duration = duration;
	return TRUE;
}
Example #18
0
File: asap-sdl.c Project: epi/asap
static void process_file(const char *input_file)
{
	FILE *fp;
	static unsigned char module[ASAPInfo_MAX_MODULE_LENGTH];
	int module_len;
	ASAP *asap;
	const ASAPInfo *info;
	SDL_AudioSpec desired;

	fp = fopen(input_file, "rb");
	if (fp == NULL)
		fatal_error("cannot open %s", input_file);
	module_len = fread(module, 1, sizeof(module), fp);
	fclose(fp);

	asap = ASAP_New();
	if (!ASAP_Load(asap, input_file, module, module_len))
		fatal_error("%s: unsupported file", input_file);
	info = ASAP_GetInfo(asap);
	if (song < 0)
		song = ASAPInfo_GetDefaultSong(info);
	if (!ASAP_PlaySong(asap, song, -1))
		fatal_error("%s: PlaySong failed", input_file);
	print_header("Name", ASAPInfo_GetTitle(info));
	print_header("Author", ASAPInfo_GetAuthor(info));
	print_header("Date", ASAPInfo_GetDate(info));

	if (SDL_Init(SDL_INIT_AUDIO) != 0)
		sdl_error("SDL_Init");
	desired.freq = ASAP_SAMPLE_RATE;
	desired.format = AUDIO_S16LSB;
	desired.channels = ASAPInfo_GetChannels(info);
	desired.samples = 4096;
	desired.callback = audio_callback;
	desired.userdata = asap;
	if (SDL_OpenAudio(&desired, NULL) != 0)
		sdl_error("SDL_OpenAudio");
	SDL_PauseAudio(0);
	printf(" playing - press Enter to quit\n");
	getchar();
	SDL_Quit();
}
Example #19
0
static gboolean play_start(InputPlayback *playback, const char *filename, VFSFile *file, int start_time, int stop_time, gboolean pause)
{
	int song = -1;
	unsigned char module[ASAPInfo_MAX_MODULE_LENGTH];
	int module_len;
	gboolean ok;
	const ASAPInfo *info;
	int channels;

#if _AUD_PLUGIN_VERSION >= 10
	char *real_filename = filename_split_subtune(filename, &song);
	if (real_filename != NULL)
		filename = real_filename;
#endif
	module_len = load_module(filename, file, module);
	ok = module_len > 0 && ASAP_Load(asap, filename, module, module_len);
#if _AUD_PLUGIN_VERSION >= 10
	g_free(real_filename);
#endif
	if (!ok)
		return FALSE;

	info = ASAP_GetInfo(asap);
	channels = ASAPInfo_GetChannels(info);
	if (song > 0)
		song--;
	else
		song = ASAPInfo_GetDefaultSong(info);
	if (stop_time < 0)
		stop_time = ASAPInfo_GetDuration(info, song);
	if (!ASAP_PlaySong(asap, song, stop_time))
		return FALSE;
	if (start_time > 0)
		ASAP_Seek(asap, start_time);

	if (!playback->output->open_audio(BITS_PER_SAMPLE == 8 ? FMT_U8 : FMT_S16_LE, ASAP_SAMPLE_RATE, channels))
		return FALSE;
	playback->set_params(playback,
#if _AUD_PLUGIN_VERSION < 18
		NULL, 0,
#endif
		0, ASAP_SAMPLE_RATE, channels);
	if (pause)
		playback->output->pause(TRUE);
	playing = TRUE;
	playback->set_pb_ready(playback);

	for (;;) {
		static unsigned char buffer[4096];
		int len;
		pthread_mutex_lock(&control_mutex);
		if (!playing) {
			pthread_mutex_unlock(&control_mutex);
			break;
		}
		len = ASAP_Generate(asap, buffer, sizeof(buffer), BITS_PER_SAMPLE == 8 ? ASAPSampleFormat_U8 : ASAPSampleFormat_S16_L_E);
		pthread_mutex_unlock(&control_mutex);
		if (len <= 0) {
#if _AUD_PLUGIN_VERSION < 18
			playback->eof = TRUE;
#endif
			break;
		}
#if _AUD_PLUGIN_VERSION >= 14
		playback->output->write_audio(buffer, len);
#else
		playback->pass_audio(playback, BITS_PER_SAMPLE == 8 ? FMT_U8 : FMT_S16_LE, channels, len, buffer, NULL);
#endif
	}

#if _AUD_PLUGIN_VERSION_MIN < 40
	while (playing && playback->output->buffer_playing())
		g_usleep(10000);
#endif
	pthread_mutex_lock(&control_mutex);
	playing = FALSE;
	pthread_mutex_unlock(&control_mutex);
#if _AUD_PLUGIN_VERSION_MIN < 40
	playback->output->close_audio();
#endif
	return TRUE;
}
Example #20
0
	t_uint32 get_subsong_count()
	{
		return ASAPInfo_GetSongs(ASAP_GetInfo(asap));
	}
Example #21
0
int EMSCRIPTEN_KEEPALIVE asap_getInfo() {
    info= ASAP_GetInfo(getAsap());
	return 0;
}