Esempio n. 1
0
void MPEGaudio:: Skip(float seconds)
{
	/* Called only when there is no timestamp info in the MPEG */
	printf("Audio: Skipping %f seconds...\n", seconds);
	while (seconds > 0)
	{
		seconds -= (float) samplesperframe / ((float) frequencies[version][frequency]*(1+inputstereo));
		if (!loadheader()) break;
	}
}
Esempio n. 2
0
MPEGaudio:: MPEGaudio(MPEGstream *stream, bool initSDL) : sdl_audio(initSDL)
{
    /* Initialize MPEG audio */
    mpeg = stream;
    initialize();

    /* Just be paranoid.  If all goes well, this will be set to true */
    valid_stream = false;

    /* Analyze the MPEG audio stream */
    if ( loadheader() ) {
        SDL_AudioSpec wanted;
        WantedSpec(&wanted);

        /* Calculate the samples per frame */
        samplesperframe = 32*wanted.channels;
        if( layer == 3 ) {
            samplesperframe *= 18;
            if ( version == 0 ) {
                samplesperframe *= 2;
            }
        } else {
            samplesperframe *= SCALEBLOCK;
            if ( layer == 2 ) {
                samplesperframe *= 3;
            }
        }
        if ( sdl_audio ) {
            /* Open the audio, get actual audio hardware format and convert */
            bool audio_active;
            SDL_AudioSpec actual;
            audio_active = (SDL_OpenAudio(&wanted, &actual) == 0);
            if ( audio_active ) {
                ActualSpec(&actual);
                valid_stream = true;
            } else {
                SetError(SDL_GetError());
            }
            SDL_PauseAudio(0);
        } else { /* The stream is always valid if we don't initialize SDL */
            valid_stream = true; 
        }
        Volume(100);
    }

    /* For using system timestamp */
    for (int i=0; i<N_TIMESTAMPS; i++)
      timestamp[i] = -1;
}
Esempio n. 3
0
void
MPEGaudio:: Skip(float seconds)
{
#ifdef THREADED_AUDIO
    /* Stop the decode thread */
    StopDecoding();
#endif

    /* Called only when there is no timestamp info in the MPEG */
    //printf("Audio: Skipping %f seconds...\n", seconds);
    while(seconds > 0)
    {
        seconds -= (float) samplesperframe / ((float) frequencies[version][frequency]*(1+inputstereo));
        if(!loadheader()) break;
    }

#ifdef THREADED_AUDIO
    StartDecoding();
#endif
}
Esempio n. 4
0
MPEGaudio:: MPEGaudio(MPEGstream *stream, bool initSDL) : sdl_audio(initSDL)
{
	/* Initialize MPEG audio */
	mpeg = stream;
	initialize();

	/* Just be paranoid.  If all goes well, this will be set to true */
	valid_stream = false;

	/* Analyze the MPEG audio stream */
	if ( loadheader() )
	{
		PSPL_AUDIO_SPEC wanted;
		WantedSpec(&wanted);

		/* Calculate the samples per frame */
		samplesperframe = 32 * wanted.channels;
		if ( layer == 3 )
		{
			samplesperframe *= 18;
			if ( version == 0 )
			{
				samplesperframe *= 2;
			}
		}
		else
		{
			samplesperframe *= SCALEBLOCK;
			if ( layer == 2 )
			{
				samplesperframe *= 3;
			}
		}
		if ( sdl_audio )
		{
			/* ていうか、ここでSDL audio ( PSPL_OpenAudio() )呼ばれると, SDL mixer 的には都合が悪い */
			/* Open the audio, get actual audio hardware format and convert */
			bool audio_active;
			PSPL_AUDIO_SPEC actual;
			audio_active = (PSPL_OpenAudio(&wanted, &actual) == 0);
			if ( audio_active )
			{
				ActualSpec(&actual);
				valid_stream = true;
			}
			else
			{
				smpeg_SetError_bbb(SDL_GetError());
			}
			PSPL_PauseAudio(0);
		}
		else 	/* The stream is always valid if we don't initialize SDL */
		{
			valid_stream = true;
		}
		//volume = (SDL_MIX_MAXVOLUME);//Volume(100);
	}

	/* For using system timestamp */
	{
		int i;
		for (i=0; i<N_TIMESTAMPS; i++)
		{	timestamp[i] = -1;}
	}
}
Esempio n. 5
0
MPEGaudio:: MPEGaudio(MPEGstream *stream, bool initSDL)
    : sdl_audio(initSDL)
    , mpeg(stream)
    , valid_stream(0)
    , stereo(false)
    , rate_in_s(0.0)
    , frags_playing(0)
    , frag_time(0)
#ifdef THREADED_AUDIO
    , decoding(false)
    , decode_thread(NULL)
#endif
{
    memset(&sideinfo, '\0', sizeof (sideinfo));

    /* Initialize MPEG audio */
    initialize();

    /* Just be paranoid.  If all goes well, this will be set to true */
    valid_stream = false;

    /* Analyze the MPEG audio stream */
    if ( loadheader() ) {
        SDL_AudioSpec wanted;
        WantedSpec(&wanted);

        /* Calculate the samples per frame */
        samplesperframe = 32*wanted.channels;
        if( layer == 3 ) {
            samplesperframe *= 18;
            if ( version == 0 ) {
                samplesperframe *= 2;
            }
        } else {
            samplesperframe *= SCALEBLOCK;
            if ( layer == 2 ) {
                samplesperframe *= 3;
            }
        }
        if ( sdl_audio ) {
            /* Open the audio, get actual audio hardware format and convert */
            bool audio_active;
            SDL_AudioSpec actual;
            audio_active = (SDL_OpenAudio(&wanted, &actual) == 0);
            if ( audio_active ) {
                ActualSpec(&actual);
                valid_stream = true;
            } else {
                SetError(SDL_GetError());
            }
            SDL_PauseAudio(0);
        } else { /* The stream is always valid if we don't initialize SDL */
            valid_stream = true; 
        }
        Volume(100);
    }

    /* For using system timestamp */
    for (int i=0; i<N_TIMESTAMPS; i++)
      timestamp[i] = -1;
}
Esempio n. 6
0
static int
transfer(			/* transfer a Radiance picture */
	char	*ospec
)
{
	char	oname[PATH_MAX];
	FILE	*fp;
	int	order;
	int	xmax, ymax;
	COLR	*scanin;
	int	y;
					/* get header info. */
	if (!(y = loadheader(stdin)))
		return(0);
	if (y < 0 || (order = fgetresolu(&xmax, &ymax, stdin)) < 0) {
		fprintf(stderr, "%s: bad input format\n", progname);
		exit(1);
	}
					/* did we pass the target frame? */
	if (findframe && findframe < frameno)
		return(0);
					/* allocate scanline */
	scanin = (COLR *)tempbuffer(xmax*sizeof(COLR));
	if (scanin == NULL) {
		perror(progname);
		exit(1);
	}
					/* skip frame? */
	if (findframe > frameno) {
		for (y = ymax; y--; )
			if (freadcolrs(scanin, xmax, stdin) < 0) {
				fprintf(stderr,
					"%s: error reading input picture\n",
						progname);
				exit(1);
			}
		return(1);
	}
					/* open output file/command */
	if (ospec == NULL) {
		strcpy(oname, "<stdout>");
		fp = stdout;
	} else {
		sprintf(oname, ospec, frameno);
		if (oname[0] == '!') {
			if ((fp = popen(oname+1, "w")) == NULL) {
				fprintf(stderr, "%s: cannot start \"%s\"\n",
						progname, oname);
				exit(1);
			}
		} else {
			if (!force && access(oname, 0) >= 0) {
				fprintf(stderr,
					"%s: output file \"%s\" exists\n",
						progname, oname);
				exit(1);
			}
			if ((fp = fopen(oname, "w")) == NULL) {
				fprintf(stderr, "%s: ", progname);
				perror(oname);
				exit(1);
			}
		}
	}
	SET_FILE_BINARY(fp);
	dumpheader(fp);			/* put out header */
	fputs(progname, fp);
	if (bradj)
		fprintf(fp, " -e %+d", bradj);
	if (!doflat)
		fputs(" -r", fp);
	fputc('\n', fp);
	if (bradj)
		fputexpos(pow(2.0, (double)bradj), fp);
	fputc('\n', fp);
	fputresolu(order, xmax, ymax, fp);
					/* transfer picture */
	for (y = ymax; y--; ) {
		if (freadcolrs(scanin, xmax, stdin) < 0) {
			fprintf(stderr, "%s: error reading input picture\n",
					progname);
			exit(1);
		}
		if (bradj)
			shiftcolrs(scanin, xmax, bradj);
		if (doflat)
			putbinary((char *)scanin, sizeof(COLR), xmax, fp);
		else
			fwritecolrs(scanin, xmax, fp);
		if (ferror(fp)) {
			fprintf(stderr, "%s: error writing output to \"%s\"\n",
					progname, oname);
			exit(1);
		}
	}
					/* clean up */
	if (oname[0] == '!')
		pclose(fp);
	else if (ospec != NULL)
		fclose(fp);
	return(1);
}
Esempio n. 7
0
void playfile(FIL* fp)
{
	FRESULT res;
	DWORD size;
	UINT rsize;
	UINT rb;

	size = loadheader(fp);
	if (size < 1024) return;

	usart_write_string("loadheader : OK\r\n");

	res = f_read(fp, buffer, 256 - (fp->fptr % 256) , &rb);
	size -= rb;
	playcnt = rb;
	if (res != FR_OK) return;

	res = f_read(fp, buffer+256, 256, &rb);
	size -= rb;
	readcnt = rb;
	if (res != FR_OK || rb != 256) return;

	playb = readb = 0;
	playidx = 0;

	usart_write_string("playfile : start\r\n");

	startplayisr();

	for (;;) {
		uint8_t p, r;
		do {
			cli();
			p = playb;
			r = readb;
			sei();
		} while (p == r);

		rsize = (size > 256) ? 256 : (UINT)size;
		res  = f_read(fp, buffer + ((uint16_t)readb << 8), rsize, &rb);
		if (res != FR_OK) break;

		size -= rb;

		cli();
		readb = playb;
		readcnt = rb;
		sei();

		if (rb != 256) break;
	}

	while (playcnt) ;

	stopplayisr();

	usart_write_string("playfile : play end\r\n");

	/* Center Level */
	OCR2B = 125;
}