Demo entry 6718891

mytest

   

Submitted by anonymous on Mar 07, 2018 at 11:50
Language: C++. Code size: 2.1 kB.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "SPAudioTrack.h"

using namespace audio;

int sine_8k_mono_s16_8ms_size = 128;
unsigned char sine_8k_mono_s16_8ms_addr[] =
{
	0x00, 0x00, 0x8B, 0x0C, 0xF8, 0x18, 0x27, 0x25, 0xFB, 0x30, 0x56, 0x3C, 0x1C, 0x47, 0x33, 0x51,
	0x81, 0x5A, 0xF1, 0x62, 0x6C, 0x6A, 0xE1, 0x70, 0x40, 0x76, 0x7C, 0x7A, 0x89, 0x7D, 0x61, 0x7F,
	0xFE, 0x7F, 0x61, 0x7F, 0x89, 0x7D, 0x7C, 0x7A, 0x40, 0x76, 0xE1, 0x70, 0x6C, 0x6A, 0xF1, 0x62,
	0x81, 0x5A, 0x33, 0x51, 0x1C, 0x47, 0x56, 0x3C, 0xFB, 0x30, 0x27, 0x25, 0xF8, 0x18, 0x8B, 0x0C,
	0x00, 0x00, 0x75, 0xF3, 0x08, 0xE7, 0xD9, 0xDA, 0x05, 0xCF, 0xAA, 0xC3, 0xE4, 0xB8, 0xCD, 0xAE,
	0x7F, 0xA5, 0x0F, 0x9D, 0x94, 0x95, 0x1F, 0x8F, 0xC0, 0x89, 0x84, 0x85, 0x77, 0x82, 0x9F, 0x80,
	0x02, 0x80, 0x9F, 0x80, 0x77, 0x82, 0x84, 0x85, 0xC0, 0x89, 0x1F, 0x8F, 0x94, 0x95, 0x0F, 0x9D,
	0x7F, 0xA5, 0xCD, 0xAE, 0xE4, 0xB8, 0xAA, 0xC3, 0x05, 0xCF, 0xD9, 0xDA, 0x08, 0xE7, 0x75, 0xF3,
};

int main(int argc, char* argv[])
{
	SPAudioTrack* track = NULL;
	int i = 0, ret = 0, times = 1000;

        track = SPAudioTrack::create("sink0", 
                                                         AUDIO_TAG_ALTER_AUDIO, 
                                                         8000, 
                                                         AUDIO_FMT_S16, 
                                                         AUDIO_CHL_MONO,
                                                         160/*buffer 160ms*/);
	if (NULL == track)
	{
		printf("create track failed\n");
		exit(-1);
	}

	track->setVolume(80); // set default volume.

	do
	{
		ret = track->write(sine_8k_mono_s16_8ms_addr, sine_8k_mono_s16_8ms_size);
	}while (ret == sine_8k_mono_s16_8ms_size);

	track->start();

	do
	{
		ret = track->write(sine_8k_mono_s16_8ms_addr, sine_8k_mono_s16_8ms_size);
		if (ret < sine_8k_mono_s16_8ms_size)
		{
			usleep(8*1000);
		}
		else
		{
			times--;
		}
	}while(times>0);

	track->stop();

	SPAudioTrack::destroy(track);
	return 0;
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).