slesTestSendToPresetReverb.cpp revision c2303eb5497c488db786dcb2b8514db229452536
100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi/* 200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * Copyright (C) 2010 The Android Open Source Project 300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * 400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * Licensed under the Apache License, Version 2.0 (the "License"); 500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * you may not use this file except in compliance with the License. 600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * You may obtain a copy of the License at 700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * 800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * http://www.apache.org/licenses/LICENSE-2.0 900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * 1000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * Unless required by applicable law or agreed to in writing, software 1100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * distributed under the License is distributed on an "AS IS" BASIS, 1200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * See the License for the specific language governing permissions and 1400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * limitations under the License. 1500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi */ 1600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 1700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#include <stdlib.h> 1800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#include <stdio.h> 1900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#include <string.h> 2000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#include <unistd.h> 2100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#include <sys/time.h> 2200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#include <fcntl.h> 2300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 2400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#include "SLES/OpenSLES.h" 2500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#ifdef ANDROID 2600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#include "SLES/OpenSLES_Android.h" 2700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#endif 2800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 2900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 3000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#define MAX_NUMBER_INTERFACES 3 3100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 3200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#define TIME_S_BETWEEN_SETTING_CHANGE 5 3300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 3400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi//----------------------------------------------------------------- 3500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi/* Exits the application if an error is encountered */ 3600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#define ExitOnError(x) ExitOnErrorFunc(x,__LINE__) 3700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 3800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivivoid ExitOnErrorFunc( SLresult result , int line) 3900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi{ 4000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi if (SL_RESULT_SUCCESS != result) { 4100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stderr, "%lu error code encountered at line %d, exiting\n", result, line); 42c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten exit(EXIT_FAILURE); 4300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi } 4400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi} 4500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 4600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 4700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi//----------------------------------------------------------------- 4800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 4900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi/* Play an audio path and feed a global reverb */ 5000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivivoid TestSendToPresetReverb( SLObjectItf sl, const char* path, int preset, SLmillibel directLevel, 5100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLmillibel sendLevel) 5200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi{ 5300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLresult result; 5400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLEngineItf EngineItf; 5500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 5600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Objects this application uses: one player and an ouput mix */ 5700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLObjectItf player, outputMix; 5800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 5900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Source of audio data to play */ 6000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLDataSource audioSource; 6100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#ifdef ANDROID 6200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLDataLocator_AndroidFD locatorFd; 6300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#else 6400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLDataLocator_URI locatorUri; 6500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#endif 6600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLDataFormat_MIME mime; 6700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 6800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Data sinks for the audio player */ 6900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLDataSink audioSink; 7000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLDataLocator_OutputMix locator_outputmix; 7100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 7200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Interfaces for the audio player */ 7300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLPlayItf playItf; 7400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLEffectSendItf effectSendItf; 7500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 7600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Interface for the output mix */ 7700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLPresetReverbItf reverbItf; 7800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 7900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLboolean required[MAX_NUMBER_INTERFACES]; 8000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLInterfaceID iidArray[MAX_NUMBER_INTERFACES]; 8100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 8200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Get the SL Engine Interface which is implicit */ 8300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*sl)->GetInterface(sl, SL_IID_ENGINE, (void*)&EngineItf); 8400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 8500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 8600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Initialize arrays required[] and iidArray[] */ 8700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi for (int i=0 ; i < MAX_NUMBER_INTERFACES ; i++) { 8800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi required[i] = SL_BOOLEAN_FALSE; 8900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi iidArray[i] = SL_IID_NULL; 9000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi } 9100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 9200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* ------------------------------------------------------ */ 9300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Configuration of the output mix */ 9400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 9500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Set arrays required[] and iidArray[] for required interfaces */ 9600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi required[0] = SL_BOOLEAN_TRUE; 9700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi iidArray[0] = SL_IID_PRESETREVERB; 9800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 9900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Create Output Mix object to be used by the player */ 10000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*EngineItf)->CreateOutputMix(EngineItf, &outputMix, 1, iidArray, required); 10100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 10200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 10300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Realize the Output Mix object in synchronous mode */ 10400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*outputMix)->Realize(outputMix, SL_BOOLEAN_FALSE); 10500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 10600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 10700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Get the SLPresetReverbItf for the output mix */ 10800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*outputMix)->GetInterface(outputMix, SL_IID_PRESETREVERB, (void*)&reverbItf); 10900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 11000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 11100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Setup the data sink structure */ 11200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi locator_outputmix.locatorType = SL_DATALOCATOR_OUTPUTMIX; 11300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi locator_outputmix.outputMix = outputMix; 11400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi audioSink.pLocator = (void*)&locator_outputmix; 11500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi audioSink.pFormat = NULL; 11600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 11700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Select the reverb preset */ 11800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "\nUsing preset "); 11900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi switch(preset) { 12000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi case SL_REVERBPRESET_NONE: 12100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "SL_REVERBPRESET_NONE, don't expect to hear reverb\n"); 12200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi break; 12300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi case SL_REVERBPRESET_SMALLROOM: fprintf(stdout, "SL_REVERBPRESET_SMALLROOM\n"); break; 12400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi case SL_REVERBPRESET_MEDIUMROOM: fprintf(stdout, "SL_REVERBPRESET_MEDIUMROOM\n"); break; 12500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi case SL_REVERBPRESET_LARGEROOM: fprintf(stdout, "SL_REVERBPRESET_LARGEROOM\n"); break; 12600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi case SL_REVERBPRESET_MEDIUMHALL: fprintf(stdout, "SL_REVERBPRESET_MEDIUMHALL\n"); break; 12700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi case SL_REVERBPRESET_LARGEHALL: fprintf(stdout, "SL_REVERBPRESET_LARGEHALL\n"); break; 12800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi case SL_REVERBPRESET_PLATE: fprintf(stdout, "SL_REVERBPRESET_PLATE\n"); break; 12900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi default: 13000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "unknown, use at your own risk\n"); break; 13100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi } 13200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*reverbItf)->SetPreset(reverbItf, preset); 13300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 13400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 13500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* ------------------------------------------------------ */ 13600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Configuration of the player */ 13700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 13800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Set arrays required[] and iidArray[] for required interfaces */ 13900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* (SLPlayItf is implicit) */ 14000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi required[0] = SL_BOOLEAN_TRUE; 14100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi iidArray[0] = SL_IID_PREFETCHSTATUS; 14200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi required[1] = SL_BOOLEAN_TRUE; 14300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi iidArray[1] = SL_IID_EFFECTSEND; 14400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 14500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#ifdef ANDROID 14600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Setup the data source structure for the URI */ 14700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi locatorFd.locatorType = SL_DATALOCATOR_ANDROIDFD; 14800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi int fd = open(path, O_RDONLY); 14900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi if (fd == -1) { 15000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(SL_RESULT_RESOURCE_ERROR); 15100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi } 15200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi locatorFd.fd = (SLint32) fd; 15300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi locatorFd.length = SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE; 15400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi locatorFd.offset = 0; 15500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#else 15600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi locatorUri.locatorType = SL_DATALOCATOR_URI; 15700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi locatorUri.URI = (SLchar *) path; 15800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#endif 15900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 16000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi mime.formatType = SL_DATAFORMAT_MIME; 16100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* this is how ignored mime information is specified, according to OpenSL ES spec 16200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi * in 9.1.6 SLDataFormat_MIME and 8.23 SLMetadataTraversalItf GetChildInfo */ 16300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi mime.mimeType = (SLchar*)NULL; 16400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi mime.containerType = SL_CONTAINERTYPE_UNSPECIFIED; 16500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 16600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi audioSource.pFormat = (void*)&mime; 16700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#ifdef ANDROID 16800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi audioSource.pLocator = (void*)&locatorFd; 16900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#else 17000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi audioSource.pLocator = (void*)&locatorUri; 17100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#endif 17200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 17300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Create the audio player */ 17400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*EngineItf)->CreateAudioPlayer(EngineItf, &player, &audioSource, &audioSink, 2, 17500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi iidArray, required); 17600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 17700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 17800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Realize the player in synchronous mode. */ 17900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*player)->Realize(player, SL_BOOLEAN_FALSE); ExitOnError(result); 18000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "URI example: after Realize\n"); 18100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 18200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Get the SLPlayItf, SLPrefetchStatusItf and SLEffectSendItf interfaces for the player*/ 18300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*player)->GetInterface(player, SL_IID_PLAY, (void*)&playItf); 18400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 18500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 18600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*player)->GetInterface(player, SL_IID_EFFECTSEND, (void*)&effectSendItf); 18700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 18800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 18900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Player configured\n"); 19000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 19100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* ------------------------------------------------------ */ 19200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Playback and test */ 19300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 19400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Get duration */ 19500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLmillisecond durationInMsec = SL_TIME_UNKNOWN; 19600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*playItf)->GetDuration(playItf, &durationInMsec); 19700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 19800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi if (durationInMsec == SL_TIME_UNKNOWN) { 19900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi durationInMsec = 5000; 20000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi } 20100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 20200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Feed the output mix' reverb from the audio player using the given send level */ 20300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*effectSendItf)->EnableEffectSend(effectSendItf, reverbItf, SL_BOOLEAN_TRUE, 20400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi sendLevel); 20500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 20600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 20700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*effectSendItf)->SetDirectLevel(effectSendItf, directLevel); 20800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 20900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Set direct level to %dmB\n", directLevel); 21000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 21100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*effectSendItf)->SetSendLevel(effectSendItf, reverbItf, sendLevel); 21200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 21300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Set send level to %dmB\n", sendLevel); 21400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 21500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Start playback */ 21600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*playItf)->SetPlayState( playItf, SL_PLAYSTATE_PLAYING ); 21700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 21800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 21900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Disable preset reverb every TIME_S_BETWEEN_SETTING_CHANGE seconds */ 22000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLboolean enabled = SL_BOOLEAN_TRUE; 22100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi for(unsigned int j=0 ; j<(durationInMsec/(1000*TIME_S_BETWEEN_SETTING_CHANGE)) ; j++) { 22200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi enabled = !enabled; 22300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*reverbItf)->SetPreset(reverbItf, enabled ? preset : SL_REVERBPRESET_NONE); 22400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi if (enabled) { 22500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Reverb on\n"); 22600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi } else { 22700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Reverb off\n"); 22800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi } 22900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 23000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi usleep(TIME_S_BETWEEN_SETTING_CHANGE * 1000 * 1000); 23100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi } 23200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 23300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Make sure player is stopped */ 23400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Stopping playback\n"); 23500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*playItf)->SetPlayState(playItf, SL_PLAYSTATE_STOPPED); 23600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 23700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 23800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Destroy the player */ 23900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi (*player)->Destroy(player); 24000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 24100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Destroy Output Mix object */ 24200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi (*outputMix)->Destroy(outputMix); 24300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 24400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#ifdef ANDROID 24500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi close(fd); 24600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi#endif 24700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi} 24800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 24900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi//----------------------------------------------------------------- 25000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Triviint main(int argc, char* const argv[]) 25100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi{ 25200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLresult result; 25300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLObjectItf sl; 25400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 25500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "OpenSL ES test %s: exercises SLEffectSendItf ", argv[0]); 25600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "on AudioPlayer and SLPresetReverbItf on OutputMix.\n"); 25700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Plays the sound file designated by the given path, "); 25800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "and sends a specified amount of energy to a global reverb\n"); 25900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "(sendLevel in mB), with a given direct level (in mB).\n"); 26000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Every %d seconds, the reverb turned on and off.\n", 26100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi TIME_S_BETWEEN_SETTING_CHANGE); 26200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 26300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi if (argc < 5) { 26400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Usage: \t%s path preset directLevel sendLevel\n", argv[0]); 26500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi fprintf(stdout, "Example: \"%s /sdcard/my.mp3 6 -2000 0\" \n", argv[0]); 266c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten exit(EXIT_FAILURE); 26700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi } 26800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 26900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi SLEngineOption EngineOption[] = { 27000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi {(SLuint32) SL_ENGINEOPTION_THREADSAFE, (SLuint32) SL_BOOLEAN_TRUE} 27100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi }; 27200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 27300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = slCreateEngine( &sl, 1, EngineOption, 0, NULL, NULL); 27400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 27500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 27600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Realizing the SL Engine in synchronous mode. */ 27700667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi result = (*sl)->Realize(sl, SL_BOOLEAN_FALSE); 27800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi ExitOnError(result); 27900667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 28000667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi // intentionally not checking that levels are of correct value 28100667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi TestSendToPresetReverb(sl, argv[1], atoi(argv[2]), (SLmillibel)atoi(argv[3]), 28200667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi (SLmillibel)atoi(argv[4])); 28300667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 28400667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi /* Shutdown OpenSL ES */ 28500667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi (*sl)->Destroy(sl); 28600667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi 287c2303eb5497c488db786dcb2b8514db229452536Glenn Kasten return EXIT_SUCCESS; 28800667fcca51d62236b538e6857b7e6b923453569Jean-Michel Trivi} 289