コード例 #1
0
ファイル: sndoggvorbis.c プロジェクト: KallistiOS/kos-ports
/* sndoggvorbis_volume(...)
 *
 * function to set the volume of the streaming channel
 */
void sndoggvorbis_volume(int vol)
{
	sndoggvorbis_vol = vol;
	snd_stream_volume(stream_hnd, vol);
}
コード例 #2
0
ファイル: sndmp3_mpg123.c プロジェクト: DC-SWAT/DreamShell
/* Adjust the MP3 volume */
void sndmp3_volume(int vol) {
	snd_stream_volume(stream_hnd, vol);
}
コード例 #3
0
ファイル: sndoggvorbis.c プロジェクト: KallistiOS/kos-ports
/* sndoggvorbis_thread()
 *
 * this function is called by sndoggvorbis_mainloop and handles all the threads
 * status handling and playing functionality.
 */
void sndoggvorbis_thread()
{
	int stat;

	stream_hnd = snd_stream_alloc(NULL, SND_STREAM_BUFFER_MAX);
	assert( stream_hnd != SND_STREAM_INVALID );

	while(sndoggvorbis_status != STATUS_QUIT)
	{
		switch(sndoggvorbis_status)
		{
			case STATUS_INIT:
				sndoggvorbis_status= STATUS_READY;
				break;

			case STATUS_READY:
				printf("oggthread: waiting on semaphore\n");
				sem_wait(sndoggvorbis_halt_sem);
				printf("oggthread: released from semaphore (status=%d)\n", sndoggvorbis_status);
				break;

			case STATUS_QUEUEING: {
				vorbis_info * vi = ov_info(&vf, -1);

				snd_stream_reinit(stream_hnd, callback);
				snd_stream_queue_enable(stream_hnd);
				printf("oggthread: stream_init called\n");
				snd_stream_start(stream_hnd, vi->rate, vi->channels - 1);
				snd_stream_volume(stream_hnd, sndoggvorbis_vol);
				printf("oggthread: stream_start called\n");
				if (sndoggvorbis_status != STATUS_STOPPING)
					sndoggvorbis_status = STATUS_QUEUED;
				break;
			}

			case STATUS_QUEUED:
				printf("oggthread: queue waiting on semaphore\n");
				sem_wait(sndoggvorbis_halt_sem);
				printf("oggthread: queue released from semaphore\n");
				break;

			case STATUS_STARTING: {
				vorbis_info * vi = ov_info(&vf, -1);

				if (sndoggvorbis_queue_enabled) {
					snd_stream_queue_go(stream_hnd);
				} else {
					snd_stream_reinit(stream_hnd, callback);
					printf("oggthread: stream_init called\n");
					snd_stream_start(stream_hnd, vi->rate, vi->channels - 1);
					printf("oggthread: stream_start called\n");
				}
				snd_stream_volume(stream_hnd, sndoggvorbis_vol);
				sndoggvorbis_status=STATUS_PLAYING;
				break;
			}

			case STATUS_PLAYING:
				/* Preliminary Bitrate Code
				 * For our tests the bitrate is being set in the struct once in a
				 * while so that the user can just read out this value from the struct
				 * and use it for whatever purpose
				 */
				/* if (tempcounter==sndoggvorbis_bitrateint)
				{
					long test;
					if((test=VorbisFile_getBitrateInstant()) != -1)
					{
						sndoggvorbis_info.actualbitrate=test;
					}
					tempcounter = 0;
				}
				tempcounter++; */

				/* Stream Polling and end-of-stream detection */
				if ( (stat = snd_stream_poll(stream_hnd)) < 0)
				{
					printf("oggthread: stream ended (status %d)\n", stat);
					printf("oggthread: not restarting\n");
					snd_stream_stop(stream_hnd);

					/* Reset our PCM buffer */
					pcm_count = 0;
					last_read = 0;
					pcm_ptr = pcm_buffer;

					/* This can also happen sometimes when you stop the stream
					   manually, so we'll call this here to make sure */
					ov_clear(&vf);
					sndoggvorbis_lastfilename[0] = 0;
					sndoggvorbis_status = STATUS_READY;
					sndoggvorbis_clear_comments();
				} else {
					/* Sleep some until the next buffer is needed */
					thd_sleep(50);
				}
				break;

			case STATUS_STOPPING:
				snd_stream_stop(stream_hnd);
				ov_clear(&vf);
				/* Reset our PCM buffer */
				pcm_count = 0;
				last_read = 0;
				pcm_ptr = pcm_buffer;

				sndoggvorbis_lastfilename[0] = 0;
				sndoggvorbis_status = STATUS_READY;
				sndoggvorbis_clear_comments();
				break;
		}
	}

	snd_stream_stop(stream_hnd);
	snd_stream_destroy(stream_hnd);
	sndoggvorbis_status=STATUS_ZOMBIE;

	printf("oggthread: thread released\n");
}