change volume of a handled soundfx in cocos2d - audio

int __sfxHandle;
[[SimpleAudioEngine sharedEngine]stopEffect:__sfxHandle];
by this way I can stop the specified sound via its handle number.
but how can I do something like this ?
somethig like :
[[SimpleAudioEngine sharedEngine]setVolumeEffect:.5f Handler:__sfxHandle];
possible ?

Related

Want to make Node Red on Raspberry Pi detected Data from Arduino and React to it but unsure how to do so?

I recently made a sensor that can correctly display the distances on the Serial Monitor on the Arduino, it would continuously display the distance as I would move my hand up/down the sensor. Thing is though, I intended on connecting this to a Pi (mine being Pi 3B+), use Node Red and basically have it detect that whenever the distance was "20cm" for example, then it would go straight to a YouTube video and play it. I tried researching all over the net to see if such had been done before, but to no avail as I found content much different than what I tried to pull off with Node Red and my Arduino.
I did try on my end to set up a function on Node Red to my Arduino, using a conditional statement to detect something and print something else out.
Overview of what I tried to do on Node Red
As you can see, there was not much to add as I was initially trying to test the conditional statement I made, making it output something on the debug screen using the code below:
Contents of the function created
var newMsg = {payload:msg.payload.toString()}:
if (newMsg == 'Distance: 20cm') {
newMsg = 'Distance is 20, nice'
return newMsg;
}
return newMsg;
Even with the little test I created to return a message to the debug did not work, so I'm not sure what I'm missing here.
First, you should not be creating new message objects as a rule, this breaks flows that use things like http-in/http-response nodes that require the original message to pass from start to end.
Second, you can't compare an Object to a String and get anything meaningful. The function node probably should looks something like the following:
if (msg.payload === "Distance: 20") {
msg.payload = "Distance is 20cm, nice"
return msg;
}
Third, the input message appears to be terminated with a new line character so the test should probably be:
if (msg.payload === "Distance: 20\n") {

Custom Joystick Behavior Linux - Adding Mod Keys

I don't have much experience with this type of stuff so I wanted to get some feedback on what I should be looking into.
Here is the situation: I have a joystick (Thrustmaster T-Flight Hotas X) that has about 12 buttons. What I would like to do is be able to hold 1 of the buttons and use it as a mod key so that I could double the number of buttons I have (I would effectively have 22 buttons).
Now what is the best way to go about this? I am currently running Ubuntu 13.10. I believe the device is picked up by the usbhid driver. Now should I be trying to write a custom driver that would yield this behavior or is there a better/less complicated way of going about this - i.e. intercepting the events and modifying them on the fly - or something else I don't even know is possible.
Anyways hope I was clear. Just trying to figure out the best course of action here.
Thanks in advance.
I would just try to use the existing Linux joystick API
https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/tree/Documentation/input/joystick-api.txt?id=refs/tags/v3.9.6
then is user space you can get all the joystick events, and process them as you see fit. Specifically you can get button press events and use logic as follows:
void handle_button_y_press()
{
if (button_X_pressed)
{
do_y_function_a();
}
else
{
do_y_function_b();
}
}

FMOD surround sound openframeworks

Ok, I hope I don't mess this up, I have had a look for some answers but can't find anything. I am trying to make a simple sampler in openframeworks using the FMOD sound player in 3D mode. I can make a single instance work fine (recording a new file using libsndfilerecorder and then playing it back and moving it in surround.
However I want to have 8 layers of looping audio that I can record and replace one layer at a time in a live show. I get a lot of problems as soon as I have more than 1 layer.
The first part of my question relates to the FMOD 3D modes, it is listener relative, so I have to define the position of my listener for every sound (I would prefer to have head relative mode but I cannot make this work at all. Again this works fine when I am using a single player but with multiple players only the last listener I update actually works.
The main problem I have is that when I use multiple players I get distortion, and often a mix of other currently playing sounds (even when the microphone cannot hear them) in my new recordings. Is there an incompatability with libsndfilerecorder and FMOD?
Here I initialise the players
for (int i=0; i<CHANNEL_COUNT; i++) {
lvelocity[i].set(1, 1, 1);
lup[i].set(0, 1, 0);
lforward[i].set(0, 0, 1);
lposition[i].set(0, 0, 0);
sposition[i].set(3, 3, 2);
svelocity[i].set(1, 1, 1);
//player[1].initializeFmod();
//player[i].loadSound( "1.wav" );
player[i].setVolume(0.75);
player[i].setMultiPlay(true);
player[i].play();
setupHold[i]==false;
recording[i]=false;
channelHasFile[i]=false;
settingOsc[i]=false;
}
When I am recording I unload the file and make sure the positions of the player that is not loaded are not updating.
void fmodApp::recordingStart( int recordingId ){
if (recording[recordingId]==false) {
setupHold[recordingId]=true; //this stops the position updating
cout<<"Start recording Channel " + ofToString(recordingId+1)+" setup hold is true \n";
pt=getDateName() +".wav";
player[recordingId].stop();
player[recordingId].unloadSound();
audioRecorder.setup(pt);
audioRecorder.setFormat(SF_FORMAT_WAV | SF_FORMAT_PCM_16);
recording[recordingId]=true; //this starts the libSndFIleRecorder
}
else {
cout<<"Channel" + ofToString(recordingId+1)+" is already recording \n";
}
}
And I stop the recording like this.
void fmodApp::recordingEnd( int recordingId ){
if (recording[recordingId]=true) {
recording[recordingId]=false;
cout<<"Stop recording" + ofToString(recordingId+1)+" \n";
audioRecorder.finalize();
audioRecorder.close();
player[recordingId].loadSound(pt);
setupHold[recordingId]=false;
channelHasFile[recordingId]=true;
cout<< "File recorded channel " + ofToString(recordingId+1) + " file is called " + pt + "\n";
}
else {
cout << "Sorry track" + ofToString(recordingId+1) + "is not recording";
}
}
I am careful not to interrupt the updating process but I cannot see where I am going wrong.
Many Thanks
to deal with the distortion, i think you will need to lower the volume of each channel on playback, try setting the volume to 1/8 of the max volume. there isn't any clipping going on so if the sum of sounds > 1.0f you will clip and it will sound bad.
to deal with crosstalk when recording: i guess you have some sort of feedback going on with the output, ie the output sound is being fed back into the input channel, probably by the operating system. if you run another app that makes sound do you also get that in your recording as well? if so then that is probably your problem.
if it works with one channel, try it with just 2, instead of jumping straight up to 8 channels.
in general i would try to abstract out the playback/record logic and soundPlayer/recorder into a separate class. you have a couple of booleans there and it's really easy to make mistakes with >1 boolean. is there any way you can replace the booleans with an enum or an integer state variable?
EDIT: I didn't see the date on your question :D Suppose you managed to do it by now. Maybe it helps somebody else..
I'm not sure if I can answer everything of your question, but I can share how I've worked with 3D sound in FMOD. I haven't worked with recording though.
For my own application a user can place sounds in 3D space around himself. For this I only have one Listener and multiple Sounds. In your code you're making a listener for every sound, are you sure that is necessary? I would imagine that this causes the multiple listeners to pick up multiple sounds and output that to your soundcard. So from the second sound+listener, both listeners pick up both sounds? I'm not a 100% sure but it sounds plausible to me.
I made a class to create sound objects (and one listener). Then I use a vector to store the objects and move trough them to render them.
My class SoundBox basically holds all the necessary things for FMOD
Making a "SoundBox" object and adding it to my soundboxes vector:
SoundBox * box = new SoundBox(box_loc, box_rotation, box_color);
box->loadVideo(ofToDataPath(video_files[soundboxes.size()]));
box->loadSound(ofToDataPath(sound_files[soundboxes.size()]));
box->setVolume(1);
box->setMultiPlay(true);
box->updateSound(box_loc, box_vel);"
box->play();
soundboxes.push_back(box);
Constructor for the SoundBox. I use a similar constructor in the same class for the listener, but since the listener will always be at the origin for me, it doesn't take any arguments and just sets all the listener locations to 0. The constructor for the listener only gets called once, while the one for the Sound gets called whenever I want to make a new one. (don't mind the box_color. I'm drawing physical boxes in this case..):
SoundBox::SoundBox(ofVec3f box_location, ofVec3f box_rotation, ofColor box_color) {
_box_location = box_location;
_box_rotation = box_rotation;
_box_color = box_color;
sound_position.x = _box_location.x;
sound_position.y = _box_location.y;
sound_position.z = _box_location.z;
sound_velocity.x = 0;
sound_velocity.y = 0;
sound_velocity.z = 0;
Then I just use a for loop to loop trough them and play them if they're not playing. I also have some similar code to select them and move then around.
for(auto box = soundboxes.begin(); box != soundboxes.end(); box++){
if(!(*box)->getIsPlaying())
(*box)->play();
}
I really hoped this helped. I'm not a very experienced programmer but this is how I got FMOD with multiple sounds to work in OpenFrameworks and hope you can use some of it. I just dumped as much of my code as I could :D
My main suggestion is to make one listener instead of more. Also having a class for making the sounds is useful if you, for instance, want to relocate the sounds after the initial placement.
Hope it helps and good luck :)

FMOD channel setVolume doesn't work

I use this:
err = channel->setVolume(someVolumeBetween0and1);
Even if err is FMOD_OK, the volume doesn't change. Am I doing something wrong? Is there any way to change the volume for a sound(channel)? Is there other range for volume instead of [0, 1]?
Thanks!
EDIT: I use setVolume just after this:
err = soundSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
I found something about volume in the FMOD manual:
"When a sound is played, it will use the sound's default frequency, volume, pan, levels and priority...
To change channel attributes before the sound is audible, start the channel paused by setting the paused flag to true, and calling the relevant channel based functions. Following that, unpause the channel with Channel::setPaused."
So, right code should like this:
err = soundSystem->playSound(FMOD_CHANNEL_FREE, sound, true, &channel);
err = channel->setVolume(someVolumeBetween0and1);
err = channel->setPaused(false);
or, you can try this one also:
err = soundSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &channel);
err = channel->setVolume(someVolumeBetween0and1);
change the order of setVolume and playSound, it works in my project
I'm not 100% sure, but the sound may need to be stopped/paused before setting the volume to unlock it and resume playing the sound after the volume has been set.
Other things to check could be that the sound is being played on the correct channel (or that you are setting the volume on the correct channel). Is the sound locked? Is sound a part of a channelgroup that could be overwriting the volume (although FMOD docs say that channelgroups should scale, not overwrite)?
I had this issue using FMOD and went down a lot of these same roads. I tried pausing the sound. I wondered if it was because my sound was looped.
In the end it was entirely an application issue. I was not using the right channel object.
There is no need to pause in order to change volume. The point of playing the sound initially paused, then setting the volume to a non-default value, then unpausing the sound, is to avoid playing that sound briefly at default volume.
try this
result = channle->setPaused(false);//after you set volume

Detecting Vibration on a Table with the iPhone

is it possible to detect vibration on the iPhone? I'm trying to figure out how to detect when the user smacks a desk or table when the phone is sitting on it. I remember reading somewhere you could detect a smack on a wooden table using the mic and AVFoundation. Any ideas?
Thanks
if you go down the microphone route, something like this might do the trick:
//somewhere during setup call this line
[anAVAudioRecorder setMeteringEnabled:YES];
//then in a method used to poll the audioMeter
[anAVAudioRecorder updateMeters];
averagePower = [anAVAudioRecorder averagePowerForChannel:0];
if (averagePower > threshold ) {
[musicPlayerClass play];
}

Resources