Музыкальные инструменты

Processing, playback of audio and video
  • I'm glad you are trying something.

    Playing audio files in kolibri is not as easy as calling a system function. I attached a very basic example for you, put all the files to /hd0/1/.
    To generate sounds I used sox:

    Code: Select all

    $ sox -n -L -c 1 -b 16 -r 48000 g392.raw synth 1 sine 392
    Attachments
    Downloaded 318 times
  • Thanks a lot, Dunkaist.
    Пока мало что понятно. Буду разбираться.
    Программа SoX уже есть в демо, или её нужно скачать?
    Наверное лучше использовать RAM-диск для файлов, скорость чтения/записи там выше (imho).
    И у меня конфигурация без /HD.
  • Antonio wrote:Пока мало что понятно. Буду разбираться.
    Feel free to ask.
    Antonio wrote:Наверное лучше использовать RAM-диск для файлов, скорость чтения/записи там выше (imho).
    И у меня конфигурация без /HD.
    File paths are hardcoded as /hd0/1/... currently, you can change them to ramsisk, of course.
  • dunkaist wrote: To generate sounds I used sox:

    Code: Select all

    $ sox -n -L -c 1 -b 16 -r 48000 g392.raw synth 1 sine 392
    Есть вопрос: на каких звуковых картах это будет работать?
    У меня пока что работает только графическая часть demo Forte.
    К слову, в плейере Pixie тоже звука нет.
    Частоту 48000, указанную в примере, поддерживают не все аудиокарты, есть смысл её понизить до стандартной 44100 для большей совместимости.
    Формат файлов raw мне раньше не встречался, какие у него преимущества перед более распространенным wav?
    Ну и последнее замечание - это отсутствие поддержки клавиатуры.
    Так что, мы всё ещё далеко от цели.
    А в остальном - всё ОК, только не мешало бы побольше комментариев в коде.
    Для начинающих.
    Спасибо
  • Antonio wrote:Есть вопрос: на каких звуковых картах это будет работать?
    У меня пока что работает только графическая часть demo Forte.
    К слову, в плейере Pixie тоже звука нет.
    I tested on Qemu with HDA codec (-soundhw hda). All applications use a common audio driver, therefore first try to set up the sound in any of them, e.g. Pixie. Then all the other apps should produce sounds too.
    Antonio wrote:Частоту 48000, указанную в примере, поддерживают не все аудиокарты, есть смысл её понизить до стандартной 44100 для большей совместимости.
    I'm not sure how Infinity driver does resampling. May be Serge, its author, will address your question.
    Antonio wrote:Формат файлов raw мне раньше не встречался, какие у него преимущества перед более распространенным wav?
    Raw is not actually a file format, it's just a file extension / filename suffix suggesting that there is no internal structure in the file and samples are written as is. I.e. you don't have to decode this file. Read it into memory and play, that's it.
    Antonio wrote:Ну и последнее замечание - это отсутствие поддержки клавиатуры.
    Так что, мы всё ещё далеко от цели.
    Keyboard support is far more simpler to implement in kolibri than dealing with audio. I helped you with the harder part. Consider it as an example or a skeleton.
    Antonio wrote:А в остальном - всё ОК, только не мешало бы побольше комментариев в коде.
    Для начинающих.
    You are right, documentation is the real issue in the project. This is not an excuse even though I did the demo late at night. That's why I encourage you to not be shy and ask any related questions.
    Antonio wrote:Спасибо
    Good luck with your project.
  • dunkaist wrote:Raw is not actually a file format, it's just a file extension / filename suffix suggesting that there is no internal structure in the file and samples are written as is. I.e. you don't have to decode this file. Read it into memory and play, that's it.
    Hello Dunkaist, how did you write raw files?
  • Antonio wrote:
    dunkaist wrote:Raw is not actually a file format, it's just a file extension / filename suffix suggesting that there is no internal structure in the file and samples are written as is. I.e. you don't have to decode this file. Read it into memory and play, that's it.
    Hello Dunkaist, how did you write raw files?
    dunkaist wrote:To generate sounds I used sox:

    Code: Select all

    $ sox -n -L -c 1 -b 16 -r 48000 g392.raw synth 1 sine 392
  • Спасибо Dunkaist.
    Благодаря Вам вышла новая программа, которой мне не хватало.
    Качество звука не идеальное и работает только с мышкой.
    Будет время - доделаю клавиатуру, если получится.
    Хотел сделать более длительные звуки, но при их наложении появляется треск.
    Поэтому оставил короткие.
    Attachments
    Downloaded 304 times
    :?: :arrow: :idea:
  • Antonio,
    good job, keep going!

    Ways to make your program even better:
    1. Initialize sound driver (_InitSound@4) only once, just after the call to sysfn 68.11;
    2. Create buffer for each file and copy samples to it only once. Store buffer handles into array;
    3. Copy _SetBufferPos@8 to your sound.asm from here and set buffer position to 0 just before each call to _PlayBuffer@8.
    Before:

    Code: Select all

    for each button press, begin:
        Init driver
        Create buffer
        Set buffer
        Play buffer
    end
    After:

    Code: Select all

    Init driver
    Create buffers
    Set buffers
    for each button press, begin:
        Set buffer position to 0
        Play buffer
    end
    Antonio wrote:Хотел сделать более длительные звуки, но при их наложении появляется треск.
    Bad news is that your program has to mix sounds itself.
    Good news is that there is an example. This is not an easy task at all. May be you need to look for some theory on audio mixing to better understand what is going on in the code.
  • I'm sorry, but I don't know how to do steps 2 and 3. If you can - pls help.
  • First I declared two arrays: files and audio_bufs that contain pointers to file names and created buffers.
    Then I added a loop just after start: that loads files into memory one by one, creates audio buffers and sets the buffers with the loaded data (raw samples).
    Then I separated procedures load_file and play_file. The former is called once per file, the latter each time corresponding button is pressed and
    Finally I subtract lowest chime button id (0xabc1) from pressed button id to know which buffer to play.
    Attachments
    sound.asm (8 KiB)
    Downloaded 305 times
    forte.asm (3.61 KiB)
    Downloaded 311 times
  • Thank you. However, the sound quality has become poor. When you press any button, the first sound is good, and again - it is already bad (crackling is appeared).
  • Добавил клавиатуру: 4-0, Е-Р.
    Если интенсивно играть на клавиатуре или мышкой, то минуты через 3 звук пропадает.
    Не знаю с чем это связано.
    Attachments
    Downloaded 300 times
    :?: :arrow: :idea:
  • Новая версия :)
    Attachments
    PIANO2 (2.8 KiB)
    Downloaded 290 times
    PIANO2.ASM (14.44 KiB)
    Downloaded 274 times
    :?: :arrow: :idea:
  • Who is online

    Users browsing this forum: No registered users and 7 guests