News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

ASIO x64 minimal sample

Started by VCoder, November 27, 2023, 06:43:34 AM

Previous topic - Next topic

VCoder

This is a very minimal ASIO sample written in x64 ASM. While the code itself is fairly straightforward, I had significant difficulty in searching for working sample. To write this code, I had to comb through NAudio to get the proper understanding of ASIO.

I hope this code helps others who are searching for similar solution

You cannot view this attachment.

jj2007

Thanks, VCoder :thup:

It builds fine when replacing all C:\ in build.bat with \ (my Masm installations are not on drive C:).

However, after mov rcx,[<pAsio>] the rcx register is zero, so it crashes:

00007FF7B2F511B2 <AS | 55                              | push rbp                        | ASIO.asm:161
00007FF7B2F511B3     | 48:8BEC                         | mov rbp,rsp                     |
00007FF7B2F511B6     | 48:83EC 10                      | sub rsp,10                      |
00007FF7B2F511BA     | 48:83E4 F0                      | and rsp,FFFFFFFFFFFFFFF0        |
00007FF7B2F511BE     | 52                              | push rdx                        | rdx:main
00007FF7B2F511BF     | 48:83EC 48                      | sub rsp,48                      |
00007FF7B2F511C3     | 48:8B0D 861E0000                | mov rcx,[<pAsio>]               | ASIO.asm:162
00007FF7B2F511CA     | 48:8B01                         | mov rax,[rcx]                   | ASIO.asm:163
00007FF7B2F511CD     | FF50 38                         | call [rax+38]                   | ASIO.asm:164
00007FF7B2F511D0     | 48:83C4 48                      | add rsp,48                      |
00007FF7B2F511D4     | 5A                              | pop rdx                         | rdx:main
00007FF7B2F511D5     | C9                              | leave                           |
00007FF7B2F511D6     | C3                              | ret                             |

VCoder

Did you replace this one? This ClsID is for my creative X-fi card. For your card it may be different.



Also if you have VS2022 installed with ASMDude, you can debug line by line.

jj2007

I have no card installed, so I can't test it, sorry.

Attached a version that is better adapted to a Masm64 SDK installation. It's only 5 files instead of 18 in your original version, making use of lots of elements that come along with the Masm64 SDK anyway. The build.bat is reduced to the following:
@echo off
\masm32\bin64\ml64.exe /Zi /Zd /Zf /FR /Fm  /c AsioSample.asm
\masm32\bin64\link.exe /DEBUG /PROFILE /MACHINE:x64 /SUBSYSTEM:WINDOWS /ENTRY:main AsioSample.obj
del *.obj
@echo off
pause

Output:
Microsoft (R) Macro Assembler (x64) Version 14.10.24930.0
Copyright (C) Microsoft Corporation.  All rights reserved.

 Assembling: AsioSample.asm
ASIO.asm(12) : warning A4014:instructions and initialized data not supported in BSS segments
Microsoft (R) Incremental Linker Version 14.10.24930.0
Copyright (C) Microsoft Corporation.  All rights reserved.

There is a warning for ASIOInfo:

pAsio         dq ?
ASIOInfo      ASIODriverInfo <>
ChannelInfo   ASIO_ChannelInfo <>

The problem sits here:
ASIODriverInfo STRUCT
AsioVersion             dd 2; ; currently, 2
DriverVersion           dd 0; ; driver specific
...
That should be:
ASIODriverInfo STRUCT
AsioVersion             dd ?; ; currently, 2
DriverVersion           dd ?; ; driver specific
...

Note that without correction, the AsioVersion member will be zero, not 2. You need to set it manually.

VCoder

@jj2007 thanks for the input. Regarding using MASM64 SDK, for me it is more convenient to keep the relevant files within same folder without referencing to other locations. Second, I will be forced to learn about the usage of particular Win32 API and its structures :biggrin: .

Here is a new version which I have updated to run with ASIO4All, so anybody should be able to run ( I assume that CLSID is same for all the ASIO4All installation {232685C6-6548-49D8-846D-4141A3EF7560})

Note: With ASIO4All, the ExitProcess doesn't seems to kill the application. You need to kill it from TaskManager. If anyone figure out the reason, please let me know.