Forum Archive

Using custom sound effects.

laszlo.j.hermann

Hallo,

Can I use my "custom" effects?
I created the full collection piano CAF (90 keys) to make a small piano app. I created a modified copy of PIANO App and I want to use it with my effects (filename PIANO_01.caf .. PIANO_90.caf). The CAF files and the PIANO.py ist in the Subdirectory root/Piano/. Opening the CAF file in Phytonista "explorer" plays the CAF file.

How can I address my own CAF files in a .py script?

I'm using the following code:

for i in range(0,90):
  effect_name = 'PIANO_'+str(i+1).zfill(2)
  self.sounds.append(effect_name)
  sound.load_effect(effect_name)

unfortunately the sound.play_effect(self.sounds[index]) doesn't plays any node.

Is there any suggestion?

Thanks and cheers.

omz

If you want to use custom sound effects, the effect name has to include the filename extension (.caf in your case).

laszlo.j.hermann

many thanks it works :-)

laszlo.j.hermann

Hmmm, new effect...
Now I have no sound or sound is muted after I started a Radio App.
But the demo Piano.py works.

Loading the custom sounds:

for i in range(0,90):
           filename = 'PIANO_'+str(i+1).zfill(2)+'.caf'
           filepath = './PianoCAF/'+ filename
           self.sounds.append(filename)
           sound.load_effect(filepath)
           if os.path.exists(filepath):
               print(self.sounds[i])

File are printed also they are existing.

def touch_began(self, touch):
       sound.set_volume(0.5)    
       self.pitchmodifier = 0      
       self.nodevalue = 13 - int((self.size.w - touch.location.x) / (self.size.w/13))    
       self.start_nodeindex = 40 + self.nodevalue+(12*self.pitchmodifier)
       print('On index: '+ str(self.start_nodeindex))
       print('On sound: '+ self.sounds[self.start_nodeindex])
       self.keypressed[self.nodevalue] = self.start_nodeindex
       sound.play_effect(self.sounds[self.start_nodeindex])  
       #direct test of sound
       sound.play_effect('PIANO_42.caf')

stdout:

On index: 50
On sound: PIANO_51.caf

but no sound.
Any suggestion?

Webmaster4o

When you're running a radio app, no other sound will play. It's the same if you download a game from the App Store. No sound will play if you're running the radio app.

laszlo.j.hermann

Unfortunatly it is not the point. I already stopped every other Apps and rebooted. No sound. ( The Piano.py demo app working properly but not my one )

JonB

this may be a stupid observation, but make sure your volume is turned up, and also that the mute is not on, (hardware switch, or else from settings if you have hardware switch set to lock rotation).

your might try preloading just a few sounds, in case there is some memory implication of loading 90 sounds.

you could also try using sound.Player objects

sound.Player() -- An object-oriented music/sound player interface... Basically, you create one by passing an absolute path to the constructor. It has play, pause and stop methods, which should be self-explanatory, and a current_time attribute which can be used for scrubbing etc.

(as an aside.... how does your piano have 90 keys? I'm jealous, mine only have 88!)

are you on the beta, or in 1.5?

laszlo.j.hermann

When the hardware is muted or volume is down, the demo piano app also wouldn't work. But it is working. The memory allocation can be a reason, so I reduced the number of effects.

        if i in range(47,49):
            sound.load_effect(filepath)

but no difference.
How can I validate the success of load_effect()?

I can check the sound.Player() but I don't understand why it is not working since yesterday (without any changing in the code).

I generated the 90 sounds with Pianoteq and it was the range I defined and not the 88 keys. 😊