Board.KolibriOS.org

Official KolibriOS board
It is currently Sun Dec 15, 2019 12:54 pm

All times are UTC+03:00




Post new topic  Reply to topic  [ 42 posts ]  Go to page 1 2 3 Next
Author Message
PostPosted: Fri Feb 08, 2019 1:18 pm 
Offline

Joined: Sat Jan 19, 2019 5:17 pm
Posts: 73
Всем привет,

думаю выкладывать здесь всё, что связано с музыкальными инструментами.
Первое, что удалось найти - это пример с системным динамиком (автор неизвестен).


Attachments:
File comment: New version
PIANO4.zip [6.31 KiB]
Downloaded 36 times
piano1.ZIP [7.4 KiB]
Downloaded 50 times


Last edited by Antonio on Fri Mar 29, 2019 8:33 am, edited 2 times in total.
Top
   
PostPosted: Sat Feb 09, 2019 3:39 am 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 442
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:
$ sox -n -L -c 1 -b 16 -r 48000 g392.raw synth 1 sine 392


Attachments:
demo_for_antonio.tar.7z [79.86 KiB]
Downloaded 50 times
Top
   
PostPosted: Sat Feb 09, 2019 12:47 pm 
Offline

Joined: Sat Jan 19, 2019 5:17 pm
Posts: 73
Thanks a lot, Dunkaist.
Пока мало что понятно. Буду разбираться.
Программа SoX уже есть в демо, или её нужно скачать?
Наверное лучше использовать RAM-диск для файлов, скорость чтения/записи там выше (imho).
И у меня конфигурация без /HD.

_________________
:?: :arrow: :idea:


Top
   
PostPosted: Sat Feb 09, 2019 2:24 pm 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 442
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.


Top
   
PostPosted: Sun Feb 10, 2019 3:35 pm 
Offline

Joined: Sat Jan 19, 2019 5:17 pm
Posts: 73
dunkaist wrote:
To generate sounds I used sox:
Code:
$ sox -n -L -c 1 -b 16 -r 48000 g392.raw synth 1 sine 392

Есть вопрос: на каких звуковых картах это будет работать?
У меня пока что работает только графическая часть demo Forte.
К слову, в плейере Pixie тоже звука нет.
Частоту 48000, указанную в примере, поддерживают не все аудиокарты, есть смысл её понизить до стандартной 44100 для большей совместимости.
Формат файлов raw мне раньше не встречался, какие у него преимущества перед более распространенным wav?
Ну и последнее замечание - это отсутствие поддержки клавиатуры.
Так что, мы всё ещё далеко от цели.
А в остальном - всё ОК, только не мешало бы побольше комментариев в коде.
Для начинающих.
Спасибо

_________________
:?: :arrow: :idea:


Top
   
PostPosted: Sun Feb 10, 2019 9:01 pm 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 442
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.


Top
   
PostPosted: Thu Mar 07, 2019 10:54 am 
Offline

Joined: Sat Jan 19, 2019 5:17 pm
Posts: 73
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?

_________________
:?: :arrow: :idea:


Top
   
PostPosted: Thu Mar 07, 2019 2:08 pm 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 442
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:
$ sox -n -L -c 1 -b 16 -r 48000 g392.raw synth 1 sine 392


Top
   
PostPosted: Sat Mar 09, 2019 1:02 am 
Offline

Joined: Sat Jan 19, 2019 5:17 pm
Posts: 73
Спасибо Dunkaist.
Благодаря Вам вышла новая программа, которой мне не хватало.
Качество звука не идеальное и работает только с мышкой.
Будет время - доделаю клавиатуру, если получится.
Хотел сделать более длительные звуки, но при их наложении появляется треск.
Поэтому оставил короткие.


Attachments:
pls unpack to tmp01.zip [1.66 MiB]
Downloaded 40 times

_________________
:?: :arrow: :idea:
Top
   
PostPosted: Sat Mar 09, 2019 8:25 am 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 442
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:
for each button press, begin:
    Init driver
    Create buffer
    Set buffer
    Play buffer
end
After:
Code:
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.


Top
   
PostPosted: Sun Mar 10, 2019 12:53 am 
Offline

Joined: Sat Jan 19, 2019 5:17 pm
Posts: 73
I'm sorry, but I don't know how to do steps 2 and 3. If you can - pls help.

_________________
:?: :arrow: :idea:


Top
   
PostPosted: Sun Mar 10, 2019 3:03 am 
Offline
Mentor
User avatar

Joined: Mon Oct 19, 2009 10:58 am
Posts: 442
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 45 times
forte.asm [3.61 KiB]
Downloaded 42 times
Top
   
PostPosted: Sun Mar 10, 2019 2:07 pm 
Offline

Joined: Sat Jan 19, 2019 5:17 pm
Posts: 73
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).

_________________
:?: :arrow: :idea:


Top
   
PostPosted: Sun Mar 10, 2019 7:28 pm 
Offline

Joined: Sat Jan 19, 2019 5:17 pm
Posts: 73
Добавил клавиатуру: 4-0, Е-Р.
Если интенсивно играть на клавиатуре или мышкой, то минуты через 3 звук пропадает.
Не знаю с чем это связано.


Attachments:
pls_unpack to tmp01.zip [1.66 MiB]
Downloaded 42 times

_________________
:?: :arrow: :idea:
Top
   
PostPosted: Fri Mar 15, 2019 2:09 pm 
Offline

Joined: Sat Jan 19, 2019 5:17 pm
Posts: 73
Новая версия :)


Attachments:
PIANO2 [2.8 KiB]
Downloaded 37 times
PIANO2.ASM [14.44 KiB]
Downloaded 38 times

_________________
:?: :arrow: :idea:
Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 42 posts ]  Go to page 1 2 3 Next

All times are UTC+03:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited