Author Topic: HOW do i sample (not play) audio?  (Read 9973 times)

0 Members and 1 Guest are viewing this topic.

Offline Parkland

  • Newbie
  • Posts: 51
    • View Profile
HOW do i sample (not play) audio?
« on: April 04, 2020, 11:45:44 pm »
I searched high and low.
tearing hair out.

Is there a qb64 function i'm missing?
How do you read the line input or microphone line?

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #1 on: April 05, 2020, 06:42:50 am »
Hi Parkland,

Well i would previously have sent you a link to my SFML library wrapper but for the life of me i cant make it compile! Ill have a look at creating new wrappers for SFML 2.5 at some point soon but i wouldnt hold my breath if i were you!

Ive attached my old wrapper and relevant file for anyone who wants to try and get it to work!

Unseen

Offline Parkland

  • Newbie
  • Posts: 51
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #2 on: April 07, 2020, 12:55:11 am »
Ok very cool thanks :)

I'm trying to figure it out, stumped on this.....

Offline Parkland

  • Newbie
  • Posts: 51
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #3 on: April 07, 2020, 12:56:12 am »
Or are you saying it needs to be compiled before it will work

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #4 on: April 07, 2020, 03:31:43 am »
Theres a problem with QB64, It seems that it can no longer link to libraries included in external libraries so this wont compile until that gets fixed, the fact it cant find your libs in declare library is worrying though, i think its cause youve got one too many \ in  your decleration.

Try

Code: QB64: [Select]
  1. DECLARE LIBRARY "SFML_Audio_Wrapper", "sfml\libsfml-audio"

Once the linking problem gets resolved with QB64 this  library should work again, until then i dont know what to suggest.

Unseen

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #5 on: April 07, 2020, 02:19:38 pm »
Hi Unseen Machine, IDE can this Library type, but it returns this error for me:

In file included from ..\\temp\\regsf.txt:1,
                 from qbx.cpp:1076:
e:/QB64 1.4/SFML_Audio_Wrapper.h:7:10: fatal error: Sfml/Audio.hpp: No such file or directory
 #include <Sfml/Audio.hpp>
          ^~~~~~~~~~~~~~~~
compilation terminated.
 
But the file on that location exist...

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #6 on: April 07, 2020, 06:20:20 pm »
Quote
In file included from ..\\temp\\regsf.txt:1,
                 from qbx.cpp:1076:
e:/QB64 1.4/SFML_Audio_Wrapper.h:7:10: fatal error: Sfml/Audio.hpp: No such file or directory
 #include <Sfml/Audio.hpp>
          ^~~~~~~~~~~~~~~~
compilation terminated.
 
But the file on that location exist...

Yep, thats cause QB64 no longer links to libraries included in external libraries, this is for some reason unknown to me but ive reported it and hopefully itll get fixed in ther near future.

Unseen

Offline Parkland

  • Newbie
  • Posts: 51
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #7 on: April 07, 2020, 08:16:42 pm »
I suppose an older version of qb64 might work, I might have one somewhere

Offline Parkland

  • Newbie
  • Posts: 51
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #8 on: April 07, 2020, 08:49:34 pm »
I could only find version 1.3, it didn't work either :(

Offline MB

  • Newbie
  • Posts: 7
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #9 on: April 22, 2020, 10:32:29 am »
I gave it a shot in QB64 (Windows 32-bit Version 0.980) & QB64 (Windows 32-bit Version 1.2 Revision 20171230/83). Both attempts gave me the C++ compile error.


QB64 rev 1.2 also had this remark within \\qb64\internal\temp\compilelog.txt

In file included from ..\\temp\\regsf.txt:1:0,
                 from qbx.cpp:1028:
..\\temp\\..\\..\\SFML_Audio_Wrapper.h:7:26: fatal error: SFML/Audio.hpp: No such file or directory
compilation terminated.


Unseen Machine, any chance you recall what was the last QB64 build was that worked with the SFML_16_Wrapper?


I have been trying to get this to work since January... Thought I was simply doing something wrong.

I have considering using the 'Teensy 4' as a proprietary audio capture device that would send the data through to QB64 via a serial port connection for me to further process within QB64. It would really rock if I was able to acquire audio samples directly from with QB64 useing the on hand windows resources.

-MB

Offline MB

  • Newbie
  • Posts: 7
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #10 on: April 22, 2020, 11:44:13 am »
The DSL version of QB64 (Version 0.954 Windows) does not give a compile error when using the "SFML_Audio_Wrapper.bas" example. I do get a "Line:21 Subscript out of range" error. So it is making it past that first "Sample(i&) = Sound_Get_Sample%(i&)" code without an error.

DSL QB64 version found at https://www.qb64.org/portal/historical-qb64/

I don't understand how to put this to use for accessing the audio input. I would really love to see example code of how read the audio line input or microphone line.

- MB

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #11 on: April 22, 2020, 12:19:25 pm »
Hi MB, on row 19, rewrite it as DIM Sample2(SampleCount2&) AS INTEGER, there is bad index pointer used (SampleCount&), but - after then it do nothing...

There miss example, how use declared library in the bas file.
« Last Edit: April 22, 2020, 12:21:59 pm by Petr »

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #12 on: April 22, 2020, 12:20:41 pm »
Hi MB

The last version i know that this library works with is the SDL version .954

Here's a demo of mic input, if you need more stuff like active sampling let me now and i can look into it as.

Code: QB64: [Select]
  1. '// Record 5 seconds of audio @ 36000 samples per second
  2. Mic_Start 36000
  3.  
  4. '// End the recording
  5. Mic_End
  6.  
  7. '// Play the mic sound directly
  8. Mic_Play
  9.  
  10.  
  11. '// Load the samples into an array
  12. '// This is if you want to analyse the sound in anyway or distort it or something
  13. NumSamples& = Mic_Get_SampleCount& - 1
  14. DIM Sample(NumSamples&) AS INTEGER
  15. FOR I& = 0 TO NumSamples&
  16.   Sample(I&) = Mic_Get_Sample(I&)
  17.  
  18.  
  19. '// Play the samples stored in the array using sndraw - i dont now what you need to / or * the value by to get accurate
  20. '// playback from sndraw
  21.  
  22. FOR I& = 0 TO NumSamples&
  23.   _SNDRAW Sample(I&)
  24.  
  25.  
  26.  
  27. '// Library Declerations
  28. DECLARE LIBRARY "SFML_Audio_Wrapper", "sfml\libsfml-audio"
  29.   SUB Mic_Start (BYVAL SampleRate&)
  30.   SUB Mic_End
  31.   SUB Mic_Play
  32.   SUB Mic_Pause
  33.   SUB Mic_Stop
  34.   SUB Mic_Save (Filename$)
  35.   FUNCTION Mic_Get_SampleCount&
  36.   FUNCTION Mic_Get_Sample% (BYVAL SampleNum&)
  37.   FUNCTION Sound_Load (FileName$)
  38.   FUNCTION Sound_Num_Samples
  39.   FUNCTION Sound_Get_Sample% (BYVAL SampleNum&)
  40.   SUB SNDRAW_Save (RawSnd%, BYVAL NumSamples&, BYVAL SampleRate&, BYVAL Channels&, FileName$)
  41.   FUNCTION Sound_Num_Channels&
  42.  

Unseen

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #13 on: April 22, 2020, 12:23:56 pm »
Hi Unseen, it works! Thank you very much!

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: HOW do i sample (not play) audio?
« Reply #14 on: April 22, 2020, 12:29:49 pm »
No worries, ive just dug the manual from my drop box account.

Unseen