Update Files
This commit is contained in:
		| @ -0,0 +1,65 @@ | ||||
| #include <Kore/Audio2/Audio.h> | ||||
| #include <Kore/Audio3/Audio.h> | ||||
|  | ||||
| using namespace Kore; | ||||
|  | ||||
| namespace { | ||||
| 	const int channelCount = 64; | ||||
| 	Audio3::Channel channels[channelCount]; | ||||
|  | ||||
| 	void callback(uint32_t samples) { | ||||
| 		for (int i = 0; i < channelCount; ++i) { | ||||
| 			channels[i].callback(samples); | ||||
| 		} | ||||
| 		for (int i = 0; i < samples; ++i) { | ||||
| 			float value = 0; | ||||
| 			for (int i = 0; i < channelCount; ++i) { | ||||
| 				value += *(float *)&channels[i].buffer.data[Audio2::buffer.readLocation]; | ||||
| 				channels[i].buffer.readLocation += 4; | ||||
| 				if (channels[i].buffer.readLocation >= channels[i].buffer.dataSize) { | ||||
| 					channels[i].buffer.readLocation = 0; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			*(float *)&Audio2::buffer.channels[0][Audio2::buffer.writeLocation] = value; | ||||
| 			*(float *)&Audio2::buffer.channels[1][Audio2::buffer.writeLocation] = value; | ||||
| 			Audio2::buffer.writeLocation += 1; | ||||
| 			if (Audio2::buffer.writeLocation >= Audio2::buffer.dataSize) { | ||||
| 				Audio2::buffer.writeLocation = 0; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void Audio3::init() { | ||||
| 	for (int i = 0; i < channelCount; ++i) { | ||||
| 		channels[i].active = false; | ||||
| 		channels[i].buffer.readLocation = 0; | ||||
| 		channels[i].buffer.writeLocation = 0; | ||||
| 		channels[i].buffer.dataSize = 128 * 1024; | ||||
| 		channels[i].buffer.data = new u8[channels[i].buffer.dataSize]; | ||||
| 	} | ||||
| 	Audio2::init(); | ||||
| 	Audio2::audioCallback = callback; | ||||
| } | ||||
|  | ||||
| void Audio3::update() { | ||||
| 	Audio2::update(); | ||||
| } | ||||
|  | ||||
| void Audio3::shutdown() { | ||||
| 	Audio2::shutdown(); | ||||
| } | ||||
|  | ||||
| Audio3::Channel *Audio3::createChannel(vec3 origin, AudioCallback callback) { | ||||
| 	for (int i = 0; i < channelCount; ++i) { | ||||
| 		if (!channels[i].active) { | ||||
| 			return &channels[i]; | ||||
| 		} | ||||
| 	} | ||||
| 	return nullptr; | ||||
| } | ||||
|  | ||||
| void Audio3::destroyChannel(Channel *channel) { | ||||
| 	channel->active = false; | ||||
| } | ||||
| @ -0,0 +1,43 @@ | ||||
| #ifdef KINC_WINDOWSAPP | ||||
|  | ||||
| #include <Kore/Audio3/TextToSpeech.h> | ||||
| #include <Kore/Log.h> | ||||
| #include <ppltasks.h> | ||||
|  | ||||
| using namespace Kore; | ||||
| using namespace Windows::Media::SpeechSynthesis; | ||||
| using namespace Windows::Media::Core; | ||||
| using namespace Windows::Media::Playback; | ||||
|  | ||||
| SpeechSynthesizer ^ speechSynthesizer; | ||||
| MediaPlayer ^ mediaPlayer; | ||||
|  | ||||
| void TextToSpeech::init() { | ||||
| 	speechSynthesizer = ref new SpeechSynthesizer(); | ||||
| 	// auto voices = speechSynthesizer->AllVoices; | ||||
| 	// for (int i = 0; i < voices->Size; i++) { | ||||
| 	//	auto voiceInfo = voices->GetAt(i); | ||||
| 	//	OutputDebugStringW(voiceInfo->DisplayName->Data()); | ||||
| 	//	OutputDebugStringW(voiceInfo->Description->Data()); | ||||
| 	//} | ||||
| 	mediaPlayer = ref new MediaPlayer(); | ||||
| } | ||||
|  | ||||
| Platform::String ^ | ||||
|     CharToString(const char *char_array) { | ||||
| 	    std::string s_str = std::string(char_array); | ||||
| 	    std::wstring wid_str = std::wstring(s_str.begin(), s_str.end()); | ||||
| 	    const wchar_t *w_char = wid_str.c_str(); | ||||
| 	    return ref new Platform::String(w_char); | ||||
|     } | ||||
|  | ||||
|     void TextToSpeech::speakText(const char *text) { | ||||
| 	concurrency::create_task(speechSynthesizer->SynthesizeTextToStreamAsync(CharToString(text))).then([](SpeechSynthesisStream ^ stream) { | ||||
| 		mediaPlayer->Source = MediaSource::CreateFromStream(stream, stream->ContentType); | ||||
| 		// mediaPlayer->Volume = 1; | ||||
| 		mediaPlayer->Play(); | ||||
| 		// mediaPlayer-> | ||||
| 	}); | ||||
| } | ||||
|  | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user