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
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);
}
Example #3
0
	BOOL __cdecl GetInfo(char *filename, int audioDataOffset, TrackInfo *trackInfo)
	{
		BYTE module[ASAPInfo_MAX_MODULE_LENGTH];
		int module_len;
		if (!loadModule(filename, module, &module_len))
			return FALSE;
		ASAPInfo *info = ASAPInfo_New();
		if (info == NULL)
			return FALSE;
		if (!ASAPInfo_Load(info, filename, module, module_len)) {
			ASAPInfo_Delete(info);
			return FALSE;
		}
		strcpy(trackInfo->suggestedTitle, ASAPInfo_GetTitle(info));
		trackInfo->fileSize = module_len;
		trackInfo->seekable = TRUE;
		trackInfo->hasEqualizer = FALSE;
		int duration = getSongDuration(info, ASAPInfo_GetDefaultSong(info));
		trackInfo->playingTime = duration >= 0 ? duration : -1;
		trackInfo->bitRate = 0;
		trackInfo->sampleRate = ASAP_SAMPLE_RATE;
		trackInfo->numChannels = ASAPInfo_GetChannels(info);
		trackInfo->bitResolution = BITS_PER_SAMPLE;
		strcpy(trackInfo->fileTypeDescription, "8-bit Atari music");
		ASAPInfo_Delete(info);
		return TRUE;
	}
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);
}
Example #5
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 #6
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 #7
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 #8
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;
}
Example #9
0
static void updateTech(void)
{
	char buf[16000];
	char *p = buf;
	const char *ext;
	int type;
	int i;
	ext = ASAPInfo_GetOriginalModuleExt(edited_info, saved_module, saved_module_len);
	if (ext != NULL)
		p += sprintf(p, "Composed in %s\r\n", ASAPInfo_GetExtDescription(ext));
	i = ASAPInfo_GetSongs(edited_info);
	if (i > 1) {
		p += sprintf(p, "SONGS %d\r\n", i);
		i = ASAPInfo_GetDefaultSong(edited_info);
		if (i > 0)
			p += sprintf(p, "DEFSONG %d (song %d)\r\n", i, i + 1);
	}
	p += sprintf(p, ASAPInfo_GetChannels(edited_info) > 1 ? "STEREO\r\n" : "MONO\r\n");
	p += sprintf(p, ASAPInfo_IsNtsc(edited_info) ? "NTSC\r\n" : "PAL\r\n");
	type = ASAPInfo_GetTypeLetter(edited_info);
	if (type != 0)
		p += sprintf(p, "TYPE %c\r\n", type);
	p += sprintf(p, "FASTPLAY %d (%d Hz)\r\n", ASAPInfo_GetPlayerRateScanlines(edited_info), ASAPInfo_GetPlayerRateHz(edited_info));
	if (type == 'C')
		p += sprintf(p, "MUSIC %04X\r\n", ASAPInfo_GetMusicAddress(edited_info));
	if (type != 0) {
		p = appendAddress(p, "INIT %04X\r\n", ASAPInfo_GetInitAddress(edited_info));
		p = appendAddress(p, "PLAYER %04X\r\n", ASAPInfo_GetPlayerAddress(edited_info));
		p = appendAddress(p, "COVOX %04X\r\n", ASAPInfo_GetCovoxAddress(edited_info));
	}
	i = ASAPInfo_GetSapHeaderLength(edited_info);
	if (i >= 0) {
		while (p < buf + sizeof(buf) - 17 && i + 4 < saved_module_len) {
			int start = saved_module[i] + (saved_module[i + 1] << 8);
			int end;
			if (start == 0xffff) {
				i += 2;
				start = saved_module[i] + (saved_module[i + 1] << 8);
			}
			end = saved_module[i + 2] + (saved_module[i + 3] << 8);
			p += sprintf(p, "LOAD %04X-%04X\r\n", start, end);
			i += 5 + end - start;
		}
	}
	chomp(buf);
	SendDlgItemMessage(infoDialog, IDC_TECHINFO, WM_SETTEXT, 0, (LPARAM) buf);
}
Example #10
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 #11
0
int EMSCRIPTEN_KEEPALIVE asapinfo_GetChannels() {
	return ASAPInfo_GetChannels(info);
}
    HRESULT GetData(LPCSHCOLUMNID pscid, PROPVARIANT *pvarData, BOOL vista)
    {
        if (!m_hasInfo)
            return S_FALSE;

        if (pscid->fmtid == FMTID_SummaryInformation) {
            if (pscid->pid == PIDSI_TITLE)
                return GetString(pvarData, ASAPInfo_GetTitle(m_pinfo));
            if (pscid->pid == PIDSI_AUTHOR)
                return GetAuthors(pvarData, vista);
        }
        else if (pscid->fmtid == FMTID_MUSIC) {
            if (pscid->pid == PIDSI_ARTIST)
                return GetAuthors(pvarData, vista);
            if (pscid->pid == PIDSI_YEAR) {
                int year = ASAPInfo_GetYear(m_pinfo);
                if (year < 0) {
                    pvarData->vt = VT_EMPTY;
                    return S_OK;
                }
                pvarData->vt = VT_UI8;
                pvarData->ulVal = (ULONG) year;
                return S_OK;
            }
        }
        else if (pscid->fmtid == FMTID_AudioSummaryInformation) {
            if (pscid->pid == PIDASI_TIMELENGTH) {
                int duration = ASAPInfo_GetDuration(m_pinfo, ASAPInfo_GetDefaultSong(m_pinfo));
                if (duration < 0) {
                    pvarData->vt = VT_EMPTY;
                    return S_OK;
                }
                if (g_windowsVer == WINDOWS_OLD) {
                    duration /= 1000;
                    char timeStr[16];
                    sprintf(timeStr, "%02d:%02d:%02d", duration / 3600, duration / 60 % 60, duration % 60);
                    return GetString(pvarData, timeStr);
                }
                else {
                    pvarData->vt = VT_UI8;
                    pvarData->uhVal.QuadPart = 10000ULL * duration;
                    return S_OK;
                }
            }
            if (pscid->pid == PIDASI_CHANNEL_COUNT) {
                pvarData->vt = VT_UI4;
                pvarData->ulVal = (ULONG) ASAPInfo_GetChannels(m_pinfo);
                return S_OK;
            }
        }
        else if (pscid->fmtid == CLSID_ASAPMetadataHandler) {
            if (pscid->pid == 1) {
                pvarData->vt = VT_UI4;
                pvarData->ulVal = (ULONG) ASAPInfo_GetSongs(m_pinfo);
                return S_OK;
            }
            if (pscid->pid == 2)
                return GetString(pvarData, ASAPInfo_IsNtsc(m_pinfo) ? "NTSC" : "PAL");
        }
        return S_FALSE;
    }
Example #13
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;
}