3

I'm starting work on an app that will need to create sound from lots of pre-loaded ".mid" files.

I'm using Python and Kivy to create an app, as I have made an app already with these tools and they are the only code I know. The other app I made uses no sound whatsoever.

Naturally, I want to make sure that the code I write will work cross-platform.

Right now, I'm simply trying to prove that I can create any real sound from a midi note.

I took this code suggested from another answer to a similar question using FluidSynth and Mingus:

from mingus.midi import fluidsynth

fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa")
fluidsynth.play_Note(64,0,100)

But I hear nothing and get this error:

fluidsynth: warning: Failed to pin the sample data to RAM; swapping is possible.

Why do I get this error, how do I fix it, and is this the simplest way or even right way?

ssgr
  • 393
  • 7
  • 21
bosky
  • 157
  • 3
  • 3
  • 7
  • Are you running this from Linux? Make sure your user is in the "audio" group. Also that is just a warning so it shouldn't stop the script from running so it may not actually be related to the issue of no sound. You will also want to verify that you have the alsa sound driver installed and working correctly (otherwise just removed the second argument of "alsa" from the init() call so that the OS will pick the default driver for you). – Max Worg Jan 19 '15 at 19:11

1 Answers1

2

I could be wrong but I don't think there is a "0" channel which is what you are passing as your second argument to .play_Note(). Try this:

fluidsynth.play_Note(64,1,100)

or (from some documentation)

from mingus.containers.note import Note
n = Note("C", 4)
n.channel = 1
n.velocity = 50
fluidSynth.play_Note(n)

UPDATE:

There are references to only channels 1-16 in the source code for that method with the default channel set to 1:

def play_Note(self, note, channel = 1, velocity = 100):
        """Plays a Note object on a channel[1-16] with a \
velocity[0-127]. You can either specify the velocity and channel \
here as arguments or you can set the Note.velocity and Note.channel \
attributes, which will take presedence over the function arguments."""
        if hasattr(note, 'velocity'):
            velocity = note.velocity
        if hasattr(note, 'channel'):
            channel = note.channel
        self.fs.noteon(int(channel), int(note) + 12, int(velocity))
        return True
Max Worg
  • 2,932
  • 2
  • 20
  • 35