-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Note playing ends almost instantly #1
Comments
Just tested in a Windows machine and the same thing happens without the SDL2 warning being logged. |
Thanks for your feedback. This project is currently only tested on windows, and I am going to test it on Linux and MacOS recently. According to the FluidSynth warning, this might be some libraries in FluidSynth not fully compatible with Ubuntu. If your code isn't working on windows, I think that should be the problem of the .sf2 file you are using. |
Could you provide a link to download this .sf2 file and I will test it on windows now? |
Yeah, it's right here via this link: https://filesend.standardnotes.com/send/1HEhj9ozmjuSSEfJ9p3v#MTFhNzEzNWJmMDVkMzhhZTM0MmM5 I've tried with 2 .sf2 files and both of them behave the same way |
Thanks, I have tested both of them on windows 10, both works with no problems, the play_note function with duration 10 will play for 10 seconds, and with short duration like 1/8 will ends very quickly. Do you see any warnings when install this package using pip? |
Python version is 3.9.5, I don't think I had any warnings when installing with pip EDIT: just reinstalled the package and no warnings showed up |
I developed this package in python 3.7.9, so I think maybe some required python packages of this project is not very compatible for newer python versions. But now I have installed python 3.9.5, pip install this package, and then do the same test, it still works for both sf2 files. So maybe tries to upgrade numpy to the newest version via pip because numpy is mainly used as handling raw audio data in this package. |
I'm already with the most recent version of numpy unfortunately (1.21.2). Do you use ffmpeg or avconv? I'm using ffmpeg. If you rely on avconv that could potentially be the issue |
That's a good reminder, I'm using pydub for audio rendering and exporting in this package, and pydub requires ffmpeg or libav to be installed correctly. Maybe it needs some configuration for the system environment variables, add the path to ffmpeg/bin to it, which is on windows, on Linux it might be something different. You can refer to this link which is pydub's github main page readme to see how to do it. |
I believe I installed FFmpeg correctly in Windows since I can use it from the command prompt (on Linux I'm sure it is correctly installed because I had already used it). I don't think I had libav installed. I will recheck these steps and the link you provided and will reply promptly. |
That's good, wait for your update :) |
@Rainbow-Dreamer everything is installed properly I think. I have pydub installed already so I assume libav exists somewhere too. Is there anything I can write on the command prompt to test libav? |
Just tested on another Windows machine, did all the necessary configs (installing ffmpeg, numpy, etc.), same issue persists. |
Installed pydub does not install libav or ffmpeg automatically, the pydub readme says you need to install ffmpeg or libav manually besides of pip install pydub, and add the /bin folder of ffmpeg or libav to system environment variable PATH (on windows), and according to my memory, you will need to restart the computer then to make this PATH configuration works on some windows versions. If you are using ffmpeg, then I think you don't need to install libav, because pydub only requires one of them. I am using ffmpeg and there are no libav installed on my computer, and it works due to testing. |
I will try restarting the computer and see if that works, but I don't have any warnings whatsoever @Rainbow-Dreamer |
Did not work. I wonder if it's the ffmpeg version causing issues? @Rainbow-Dreamer what's your output of
|
This is mine.
|
This might be the problem, but I think you can try |
@Rainbow-Dreamer |
Good to hear that, so this shows there are no problems with fluidsynth and pydub on windows when using this package, so this should be the problem of simpleaudio, which is the python package used to play audio data handled by pydub in this project. In pydub's readme, it is strongly recommended to use simpleaudio to play pydub's audio objects (which has not been exported yet), so I add simpleaudio to the requirements of this project when pip install, and it should works well on windows. Maybe I can add a global function for users to choose which python package used to play pydub's audio objects. You can have a look at this link which shows some python packages that could be used to play audio in pydub's readme. |
Getting some compilation issues related to fluidsynth now 🤔
Any ideas? Yeah, for now I will use the export functions and then playback the audio file. Will definitely keep assisting you here if you want. |
Thanks for your support, I am glad to hear if there are any other problems when using this package from you in the future. |
By the way, just to mention that you don't need to write |
The fluidsynth issues happened when I removed simpleaudio and uninstalled the package. So reverting that should fix it. |
Will try this tomorrow and will let you know. Thanks for your patience and guidance! |
You're welcome :) |
Switching to your ffmpeg version did not solve issue @Rainbow-Dreamer . I am also going to take a look at your musicpy package on its own, it may be better suited for my use case. Basically what I am trying to achieve is generating music via Lindenmayer Systems. You generate a string according to symbolic rules and you parse the final result to music. EDIT: Interesting, I tried to use sample code of musicpy and I cannot hear any sound at all. |
That sounds very cool, and I'm glad that you choose musicpy, since musicpy is a package that is very easy to implement mathematical and statistical algorithms in python on music theory stuffs, I recommended you to read the wiki I wrote to get full details and usages of musicpy. Thanks for your support :) |
Hi, could you try to play some notes using this package on another computer that does not use a Focusrite Audio interface and could play a mp3 file using pygame normally (on windows)? (And don't forget to set up ffmpeg for pydub) If there are no issues with the note playing, we can make sure that this issue is only a conflict of audio driver and python itself. |
Will try playing the note without having my Focusrite interface plugged in. I will give you feedback about sf2_loader on Linux for sure. Unfortunately, don't have access to a macOS machine. |
It's fine, just mention it in case you want to use it on a Mac :) |
@gildurao By the way, you actually don't need to construct a C major chord in musicpy like what you did in another issue, there are many convenient and advanced syntax for building complex chords in musicpy, you will see them in basic syntax sections of the wiki. # using chord name
myGChord = sf.mp.C('C', 5, duration=1, volume=100)
# construct a C major chord starts at C5 with all notes have duration of 1 bar and volume of 100
myGChord = sf.mp.C('Cmaj7', 5, duration=1, volume=100) # build a Cmaj7 chord
# using a string of notes
myGChord = sf.mp.chord('C5, E5, G5', duration=1, volume=100)
myGChord = sf.mp.chord('c5, e5, g5', duration=1, volume=100) # the note names could also be lowercase
myGChord = sf.mp.chord('C, E, G', duration=1, volume=100, rootpitch=5) # if no octave numbers are specified,
# then it will automatically builds up with smallest intervals possible
myGChord = sf.mp.chord('C5[1;0;100], E5[1;0;100], G5[1;0;100]') # this is an advanced syntax,
# I also recommend "translate" syntax which is even more convenient than this
# using a list of notes (could be note instances or strings representing notes)
myGChord = sf.mp.chord(['C5', 'E5', 'G5'], duration=1, volume=100)
myGChord = sf.mp.chord([sf.mp.N('C5'), sf.mp.N('E5'), sf.mp.N('G5')], duration=1, volume=100) |
Thanks for the examples! I just did that small example to understand how your library worked 😁 |
You're welcome :) |
Well, it's been a long time, I think I'm gonna close this issue, if you have any issues of this package on Linux or without having Focusrite interface plugged in, welcome to open a new issue, thanks :) |
Hello,
I tried using your library today (huge thanks btw for providing a clean way to just play sounds off .sf2 files) and when playing a note, it almost ends instantly (less than a second). Setting a duration for the note also does not fix this. Same thing happens when playing a chord. I wonder if this is because of the .sf2 file itself or because I'm running in on Ubuntu.
Python version is 3.9.5
Here's the code I used:
when running I do get a FluidSynth warning, don't know if it's related:
Let me know if you need more info. Thanks again.
The text was updated successfully, but these errors were encountered: