From 2ab22bdad1415813a3e1df329640332702272fc0 Mon Sep 17 00:00:00 2001 From: tobigun Date: Mon, 1 Sep 2008 17:01:58 +0000 Subject: - new configure/make layout: - configure/main-makefile moved to root-dir - configure-script checked in (no need to call autogen.sh on first run) - autogen.sh, m4, install.sh etc. moved to dists/autogen/ - config.guess/sub for canonical builds - unit-tests moved to test - removed delphi subdir in portaudio/-mixer - COPYING.txt/AUTHORS.txt/... added - dists/delphi7/2005 added git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1334 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/switches.inc | 0 test/test_libraries.lpi | 299 ++++++++++++++++++++++++++++++++++++++++++++++++ test/test_libraries.lpr | 31 +++++ test/testsqllite.pas | 84 ++++++++++++++ 4 files changed, 414 insertions(+) create mode 100644 test/switches.inc create mode 100644 test/test_libraries.lpi create mode 100644 test/test_libraries.lpr create mode 100644 test/testsqllite.pas (limited to 'test') diff --git a/test/switches.inc b/test/switches.inc new file mode 100644 index 00000000..e69de29b diff --git a/test/test_libraries.lpi b/test/test_libraries.lpi new file mode 100644 index 00000000..cc3a6ddf --- /dev/null +++ b/test/test_libraries.lpi @@ -0,0 +1,299 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/test_libraries.lpr b/test/test_libraries.lpr new file mode 100644 index 00000000..3e3ae380 --- /dev/null +++ b/test/test_libraries.lpr @@ -0,0 +1,31 @@ +program Test_Libraries; + +{$mode objfpc}{$H+} + +uses + Classes, + consoletestrunner, + TestSQLLite, + SQLite3 in '../lib/SQLite/SQLite3.pas', + + SQLiteTable3 in '../lib/SQLite/SQLiteTable3.pas'; + +type + + { TLazTestRunner } + + TMyTestRunner = class(TTestRunner) + protected + // override the protected methods of TTestRunner to customize its behavior + end; + +var + Application: TMyTestRunner; + +begin + Application := TMyTestRunner.Create(nil); + Application.Initialize; + Application.Title := 'FPCUnit Console test runner'; + Application.Run; + Application.Free; +end. diff --git a/test/testsqllite.pas b/test/testsqllite.pas new file mode 100644 index 00000000..b1b682d2 --- /dev/null +++ b/test/testsqllite.pas @@ -0,0 +1,84 @@ +unit TestSQLLite; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, fpcunit, testutils, testregistry, SQLiteTable3, unix; + +type + + TTest_SqlLite= class(TTestCase) + private + fSQLLite : TSQLiteDatabase; + fFileName : string; + protected + procedure SetUp; override; + procedure TearDown; override; + published + procedure Test_Random_TableExists; + procedure Test_Delete_NonExistant_Table; + procedure Test_TableExists_On_0Length_File; + end; + +implementation + +procedure TTest_SqlLite.Test_Random_TableExists; +begin + deletefile( fFileName ); + fSQLLite := TSQLiteDatabase.Create( fFileName ); + + // Test if some random table exists + check( not fSQLLite.TableExists( 'testTable'+floattostr(now()) ) , 'Randomly Named Table Should NOT Exists (In an empty database file)' ); +end; + +procedure TTest_SqlLite.Test_Delete_NonExistant_Table; +var + lSQL : String; +begin + deletefile( fFileName ); + fSQLLite := TSQLiteDatabase.Create( fFileName ); + try + lSQL := 'DROP TABLE testtable'; + fSQLLite.execsql( lSQL ); + except + exit; + end; + + Fail('SQLLite did not except when trying to delete a non existant table' ); +end; + +procedure TTest_SqlLite.Test_TableExists_On_0Length_File; +var + lSQL : String; +begin + deletefile( fFileName ); + shell('cat /dev/null > '+fFileName); + + if not fileexists( fFileName ) then + Fail('0 Length file was not created... oops' ); + + fSQLLite := TSQLiteDatabase.Create( fFileName ); + + check( not fSQLLite.TableExists( 'testTable' ) , 'Randomly Named Table Should NOT Exists' ); +end; + + +procedure TTest_SqlLite.SetUp; +begin + fFileName := 'test.db'; +// fSQLLite := TSQLiteDatabase.Create( fFileName ); +end; + + +procedure TTest_SqlLite.TearDown; +begin + freeandnil( fSQLLite ); +end; + +initialization + + RegisterTest(TTest_SqlLite); +end. + -- cgit v1.2.3 From 17c4a117949e1ab430bda520e5923346216264ae Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Fri, 15 May 2009 21:31:53 +0000 Subject: start of test programs git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1728 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/test001.pas | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 test/test001.pas (limited to 'test') diff --git a/test/test001.pas b/test/test001.pas new file mode 100644 index 00000000..4ee62690 --- /dev/null +++ b/test/test001.pas @@ -0,0 +1,84 @@ +program test001; + +{ +This program test the function glext_ExtensionSupported from unit glext. +} + +uses + SysUtils, + SDL, + gl, + glext; + +const + s1: pchar = ''; + s2: pchar = 'ext'; + s3: pchar = ' ext'; + s4: pchar = ' ext '; + s5: pchar = 'kkshf kjsfh ext'; + s6: pchar = 'fakh sajhf ext jskdhf'; + s7: pchar = 'ext jshf'; + s8: pchar = 'sdkjfh ksjhext sjdha'; + s9: pchar = 'sdkjfh ksjh extsjdha'; + s10: pchar = 'sdkjfh ksjhextsjdha'; + s11: pchar = 'sd kjf jdha'; + + e1: pchar = ''; + e2: pchar = 'ext'; + e3: pchar = 'GL_ARB_window_pos'; + + SCREEN_WIDTH = 640; + SCREEN_HEIGHT = 480; + SCREEN_BPP = 16; + +var + surface: PSDL_Surface; + videoFlags: integer; + +begin + write ('test001: Start ... '); + +// initialize SDL and OpenGL for the use of glGetString(GL_EXTENSIONS) +// within glext_ExtensionSupported. + + SDL_Init( SDL_INIT_VIDEO); + +// the flags to pass to SDL_SetVideoMode + videoFlags := SDL_OPENGL; + +// get a SDL surface + surface := SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags); + +// Initialization finished + + if glext_ExtensionSupported(e1, s1) then + writeln ('test001, 1: failed'); + if glext_ExtensionSupported(e1, s2) then + writeln ('test001, 2: failed'); + if glext_ExtensionSupported(e2, s1) then + writeln ('test001, 3: failed'); + if not glext_ExtensionSupported(e2, s2) then + writeln ('test001, 4: failed'); + if not glext_ExtensionSupported(e2, s3) then + writeln ('test001, 5: failed'); + if not glext_ExtensionSupported(e2, s4) then + writeln ('test001, 6: failed'); + if not glext_ExtensionSupported(e2, s5) then + writeln ('test001, 7: failed'); + if not glext_ExtensionSupported(e2, s6) then + writeln ('test001, 8: failed'); + if not glext_ExtensionSupported(e2, s7) then + writeln ('test001, 9: failed'); + if glext_ExtensionSupported(e2, s8) then + writeln ('test001, 10: failed'); + if glext_ExtensionSupported(e2, s9) then + writeln ('test001, 11: failed'); + if glext_ExtensionSupported(e2, s10) then + writeln ('test001, 12: failed'); + if glext_ExtensionSupported(e2, s11) then + writeln ('test001, 13: failed'); + if not glext_ExtensionSupported(e3, s1) then + writeln ('test001, 14: failed'); + + writeln ('End'); +end. \ No newline at end of file -- cgit v1.2.3 From 2c187c2f3943bfd42303bf9d84cc5569c25412b2 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Fri, 15 May 2009 23:01:30 +0000 Subject: new version of test of function glext_ExtensionSupported git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1729 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/test001.pas | 79 ++++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 42 deletions(-) (limited to 'test') diff --git a/test/test001.pas b/test/test001.pas index 4ee62690..5339f275 100644 --- a/test/test001.pas +++ b/test/test001.pas @@ -6,20 +6,21 @@ This program test the function glext_ExtensionSupported from unit glext. uses SysUtils, - SDL, - gl, - glext; + SDL in '../src/lib/JEDI-SDL/SDL/Pas/sdl.pas', + moduleloader in '../src/lib/JEDI-SDL/SDL/Pas/moduleloader.pas', + gl in '../src/lib/JEDI-SDL/OpenGL/Pas/gl.pas', + glext in '../src/lib/JEDI-SDL/OpenGL/Pas/glext.pas'; const - s1: pchar = ''; - s2: pchar = 'ext'; - s3: pchar = ' ext'; - s4: pchar = ' ext '; - s5: pchar = 'kkshf kjsfh ext'; - s6: pchar = 'fakh sajhf ext jskdhf'; - s7: pchar = 'ext jshf'; - s8: pchar = 'sdkjfh ksjhext sjdha'; - s9: pchar = 'sdkjfh ksjh extsjdha'; + s1: pchar = ''; + s2: pchar = 'ext'; + s3: pchar = ' ext'; + s4: pchar = ' ext '; + s5: pchar = 'kkshf kjsfh ext'; + s6: pchar = 'fakh sajhf ext jskdhf'; + s7: pchar = 'ext jshf'; + s8: pchar = 'sdkjfh ksjhext sjdha'; + s9: pchar = 'sdkjfh ksjh extsjdha'; s10: pchar = 'sdkjfh ksjhextsjdha'; s11: pchar = 'sd kjf jdha'; @@ -32,11 +33,13 @@ const SCREEN_BPP = 16; var - surface: PSDL_Surface; + surface: PSDL_Surface; videoFlags: integer; + testFailed: boolean; begin write ('test001: Start ... '); + testFailed := false; // initialize SDL and OpenGL for the use of glGetString(GL_EXTENSIONS) // within glext_ExtensionSupported. @@ -51,34 +54,26 @@ begin // Initialization finished - if glext_ExtensionSupported(e1, s1) then - writeln ('test001, 1: failed'); - if glext_ExtensionSupported(e1, s2) then - writeln ('test001, 2: failed'); - if glext_ExtensionSupported(e2, s1) then - writeln ('test001, 3: failed'); - if not glext_ExtensionSupported(e2, s2) then - writeln ('test001, 4: failed'); - if not glext_ExtensionSupported(e2, s3) then - writeln ('test001, 5: failed'); - if not glext_ExtensionSupported(e2, s4) then - writeln ('test001, 6: failed'); - if not glext_ExtensionSupported(e2, s5) then - writeln ('test001, 7: failed'); - if not glext_ExtensionSupported(e2, s6) then - writeln ('test001, 8: failed'); - if not glext_ExtensionSupported(e2, s7) then - writeln ('test001, 9: failed'); - if glext_ExtensionSupported(e2, s8) then - writeln ('test001, 10: failed'); - if glext_ExtensionSupported(e2, s9) then - writeln ('test001, 11: failed'); - if glext_ExtensionSupported(e2, s10) then - writeln ('test001, 12: failed'); - if glext_ExtensionSupported(e2, s11) then - writeln ('test001, 13: failed'); - if not glext_ExtensionSupported(e3, s1) then - writeln ('test001, 14: failed'); + if glext_ExtensionSupported(e1, s1) then begin writeln; write ('test001, 1: failed'); testFailed := true; end; + if glext_ExtensionSupported(e1, s2) then begin writeln; write ('test001, 2: failed'); testFailed := true; end; + if glext_ExtensionSupported(e2, s1) then begin writeln; write ('test001, 3: failed'); testFailed := true; end; + if not glext_ExtensionSupported(e2, s2) then begin writeln; write ('test001, 4: failed'); testFailed := true; end; + if not glext_ExtensionSupported(e2, s3) then begin writeln; write ('test001, 5: failed'); testFailed := true; end; + if not glext_ExtensionSupported(e2, s4) then begin writeln; write ('test001, 6: failed'); testFailed := true; end; + if not glext_ExtensionSupported(e2, s5) then begin writeln; write ('test001, 7: failed'); testFailed := true; end; + if not glext_ExtensionSupported(e2, s6) then begin writeln; write ('test001, 8: failed'); testFailed := true; end; + if not glext_ExtensionSupported(e2, s7) then begin writeln; write ('test001, 9: failed'); testFailed := true; end; + if glext_ExtensionSupported(e2, s8) then begin writeln; write ('test001, 10: failed'); testFailed := true; end; + if glext_ExtensionSupported(e2, s9) then begin writeln; write ('test001, 11: failed'); testFailed := true; end; + if glext_ExtensionSupported(e2, s10) then begin writeln; write ('test001, 12: failed'); testFailed := true; end; + if glext_ExtensionSupported(e2, s11) then begin writeln; write ('test001, 13: failed'); testFailed := true; end; + if not glext_ExtensionSupported(e3, s1) then begin writeln; write ('test001, 14: failed'); testFailed := true; end; - writeln ('End'); + if testFailed then + begin + writeln; + writeln ('test001: End'); + end + else + writeln ('End'); end. \ No newline at end of file -- cgit v1.2.3 From 90a9ee81e6f1a5481c942e5a95c3ec856bd8f6ae Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Wed, 20 May 2009 23:09:48 +0000 Subject: new version. also test of buildbot git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@1751 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/test001.pas | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/test001.pas b/test/test001.pas index 5339f275..c9ba266f 100644 --- a/test/test001.pas +++ b/test/test001.pas @@ -1,7 +1,7 @@ program test001; { -This program test the function glext_ExtensionSupported from unit glext. +This program tests the function glext_ExtensionSupported from unit glext. } uses @@ -36,6 +36,13 @@ var surface: PSDL_Surface; videoFlags: integer; testFailed: boolean; + +procedure treatTestFailure(testNumber: integer, var testFailed: boolean); +begin + writeln; + write ('test001, ', testNumber, ': failed'); + testFailed := true; +end; begin write ('test001: Start ... '); @@ -54,20 +61,20 @@ begin // Initialization finished - if glext_ExtensionSupported(e1, s1) then begin writeln; write ('test001, 1: failed'); testFailed := true; end; - if glext_ExtensionSupported(e1, s2) then begin writeln; write ('test001, 2: failed'); testFailed := true; end; - if glext_ExtensionSupported(e2, s1) then begin writeln; write ('test001, 3: failed'); testFailed := true; end; - if not glext_ExtensionSupported(e2, s2) then begin writeln; write ('test001, 4: failed'); testFailed := true; end; - if not glext_ExtensionSupported(e2, s3) then begin writeln; write ('test001, 5: failed'); testFailed := true; end; - if not glext_ExtensionSupported(e2, s4) then begin writeln; write ('test001, 6: failed'); testFailed := true; end; - if not glext_ExtensionSupported(e2, s5) then begin writeln; write ('test001, 7: failed'); testFailed := true; end; - if not glext_ExtensionSupported(e2, s6) then begin writeln; write ('test001, 8: failed'); testFailed := true; end; - if not glext_ExtensionSupported(e2, s7) then begin writeln; write ('test001, 9: failed'); testFailed := true; end; - if glext_ExtensionSupported(e2, s8) then begin writeln; write ('test001, 10: failed'); testFailed := true; end; - if glext_ExtensionSupported(e2, s9) then begin writeln; write ('test001, 11: failed'); testFailed := true; end; - if glext_ExtensionSupported(e2, s10) then begin writeln; write ('test001, 12: failed'); testFailed := true; end; - if glext_ExtensionSupported(e2, s11) then begin writeln; write ('test001, 13: failed'); testFailed := true; end; - if not glext_ExtensionSupported(e3, s1) then begin writeln; write ('test001, 14: failed'); testFailed := true; end; + if glext_ExtensionSupported(e1, s1) then treatTestFailure( 1, testFailed); + if glext_ExtensionSupported(e1, s2) then treatTestFailure( 2, testFailed); + if glext_ExtensionSupported(e2, s1) then treatTestFailure( 3, testFailed); + if not glext_ExtensionSupported(e2, s2) then treatTestFailure( 4, testFailed); + if not glext_ExtensionSupported(e2, s3) then treatTestFailure( 5, testFailed); + if not glext_ExtensionSupported(e2, s4) then treatTestFailure( 6, testFailed); + if not glext_ExtensionSupported(e2, s5) then treatTestFailure( 7, testFailed); + if not glext_ExtensionSupported(e2, s6) then treatTestFailure( 8, testFailed); + if not glext_ExtensionSupported(e2, s7) then treatTestFailure( 9, testFailed); + if glext_ExtensionSupported(e2, s8) then treatTestFailure(10, testFailed); + if glext_ExtensionSupported(e2, s9) then treatTestFailure(11, testFailed); + if glext_ExtensionSupported(e2, s10) then treatTestFailure(12, testFailed); + if glext_ExtensionSupported(e2, s11) then treatTestFailure(13, testFailed); + if not glext_ExtensionSupported(e3, s1) then treatTestFailure(14, testFailed); if testFailed then begin -- cgit v1.2.3 From 985548c51eefe40f8dbccbedb35b1736b7d5d40f Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sun, 7 Mar 2010 09:38:04 +0000 Subject: A simple test of the portaudio audio devices. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2180 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/TestPortAudioDevice.pas | 181 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 test/TestPortAudioDevice.pas (limited to 'test') diff --git a/test/TestPortAudioDevice.pas b/test/TestPortAudioDevice.pas new file mode 100644 index 00000000..3b6e1cd4 --- /dev/null +++ b/test/TestPortAudioDevice.pas @@ -0,0 +1,181 @@ +{* UltraStar Deluxe - Karaoke Game + * + * UltraStar Deluxe is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + *} + +program TestPortAudioDevice; + +{* TestPortAudioDevice does some basic tests of the portaudio libs. + * If all works, it lists all audio input and output devices and their + * characteristics. Compile and run with simple commands. + *} + +{$IFDEF FPC} + {$MODE Delphi} +{$ENDIF} + +uses + PortAudio in '../../src/lib/portaudio/portaudio.pas'; + +const + paDefaultApi = -1; + +const + ApiPreferenceOrder: +{$IF Defined(MSWINDOWS)} + // Note1: Portmixer has no mixer support for paASIO and paWASAPI at the moment + // Note2: Windows Default-API is MME, but DirectSound is faster + array[0..0] of TPaHostApiTypeId = ( paDirectSound ); +{$ELSEIF Defined(DARWIN)} + array[0..0] of TPaHostApiTypeId = ( paDefaultApi ); // paCoreAudio +{$ELSEIF Defined(UNIX)} + // Note: Portmixer has no mixer support for JACK at the moment + array[0..2] of TPaHostApiTypeId = ( paALSA, paJACK, paOSS ); +{$ELSE} + array[0..0] of TPaHostApiTypeId = ( paDefaultApi ); +{$IFEND} + +var + i: integer; + PaError: TPaError; + paApiIndex: TPaHostApiIndex; + paApiInfo: PPaHostApiInfo; + deviceIndex: TPaDeviceIndex; + deviceInfo: PPaDeviceInfo; + +function GetPreferredApiIndex(): TPaHostApiIndex; +var + i: integer; + apiIndex: TPaHostApiIndex; + apiInfo: PPaHostApiInfo; +begin + result := -1; + + // select preferred sound-API + for i:= 0 to High(ApiPreferenceOrder) do + begin + if (ApiPreferenceOrder[i] <> paDefaultApi) then + begin + // check if API is available + apiIndex := Pa_HostApiTypeIdToHostApiIndex(ApiPreferenceOrder[i]); + if (apiIndex >= 0) then + begin + // we found an API but we must check if it works + // (on linux portaudio might detect OSS but does not provide + // any devices if ALSA is enabled) + apiInfo := Pa_GetHostApiInfo(apiIndex); + if (apiInfo^.deviceCount > 0) then + begin + Result := apiIndex; + break; + end; + end; + end; + end; + + // None of the preferred APIs is available -> use default + if (result < 0) then + begin + result := Pa_GetDefaultHostApi(); + end; +end; + +begin + writeln ('Start: Test of Portaudio libs'); + writeln; + + writeln ('*** Test of Pa_Initialize and Pa_Terminate ***'); + PaError := Pa_Initialize; + if PaError = paNoError then + writeln ('Pa_Initialize: NoError') + else + writeln ('Pa_Initialize: Error No ', PaError); + + PaError := Pa_Terminate; + if PaError = paNoError then + writeln ('Pa_Terminate: NoError') + else + writeln ('Pa_Terminate: Error No: ', PaError); + writeln; + + writeln ('*** Test of GetPreferredApiIndex ***'); + PaError := Pa_Initialize; + paApiIndex := GetPreferredApiIndex(); + if (paApiIndex = -1) then + writeln ('GetPreferredApiIndex: No working Audio-API found.') + else + writeln ('GetPreferredApiIndex: working Audio-API found. No: ', paApiIndex); + PaError := Pa_Terminate; + writeln; + + writeln ('*** Test of Pa_GetHostApiInfo ***'); + PaError := Pa_Initialize; + paApiIndex := GetPreferredApiIndex(); + paApiInfo := Pa_GetHostApiInfo(paApiIndex); + writeln ('Pa_GetHostApiInfo:'); + writeln ('paApiInfo.structVersion: ', paApiInfo.structVersion); + writeln ('paApiInfo._type: ', paApiInfo._type); + writeln ('paApiInfo.name: ', paApiInfo.name); + writeln ('paApiInfo.deviceCount: ', paApiInfo.deviceCount); + writeln ('paApiInfo.defaultInputDevice: ', paApiInfo.defaultInputDevice); + writeln ('paApiInfo.defaultOutputDevice: ', paApiInfo.defaultOutputDevice); + PaError := Pa_Terminate; + writeln; + + writeln ('*** Test of Pa_HostApiDeviceIndexToDeviceIndex ***'); + PaError := Pa_Initialize; + paApiIndex := GetPreferredApiIndex(); + paApiInfo := Pa_GetHostApiInfo(paApiIndex); + for i:= 0 to paApiInfo^.deviceCount-1 do + begin + deviceIndex := Pa_HostApiDeviceIndexToDeviceIndex(paApiIndex, i); + writeln ('deviceIndex[', i, ']: ', deviceIndex); + end; + PaError := Pa_Terminate; + writeln; + + writeln ('*** Test of Pa_GetDeviceInfo ***'); +// + PaError := Pa_Initialize; + paApiIndex := GetPreferredApiIndex(); + paApiInfo := Pa_GetHostApiInfo(paApiIndex); + for i:= 0 to paApiInfo^.deviceCount - 1 do + begin + deviceIndex := Pa_HostApiDeviceIndexToDeviceIndex(paApiIndex, i); + deviceInfo := Pa_GetDeviceInfo(deviceIndex); + writeln ('deviceInfo[', i, '].name: ', deviceInfo^.name); + writeln ('deviceInfo[', i, '].structVersion: ', deviceInfo^.structVersion, ' (should be 2)'); + writeln ('deviceInfo[', i, '].hostApi: ', deviceInfo^.hostApi); + writeln ('deviceInfo[', i, '].maxInputChannels: ', deviceInfo^.maxInputChannels); + writeln ('deviceInfo[', i, '].maxOutputChannels: ', deviceInfo^.maxOutputChannels); + writeln ('deviceInfo[', i, '].defaultLowInputLatency: ', deviceInfo^.defaultLowInputLatency); + writeln ('deviceInfo[', i, '].defaultLowOutputLatency: ', deviceInfo^.defaultLowOutputLatency); + writeln ('deviceInfo[', i, '].defaultHighInputLatency: ', deviceInfo^.defaultHighInputLatency); + writeln ('deviceInfo[', i, '].defaultHighOutputLatency: ', deviceInfo^.defaultHighOutputLatency); + writeln ('deviceInfo[', i, '].defaultSampleRate: ', deviceInfo^.defaultSampleRate:5:1); + writeln; + end; + PaError := Pa_Terminate; + + writeln ('End: Test of Portaudio libs'); +end. \ No newline at end of file -- cgit v1.2.3 From 8166385818520755a05d1fa8392aab2ec2c21796 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sun, 7 Mar 2010 10:43:16 +0000 Subject: bug fix and more tests. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2181 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/TestPortAudioDevice.pas | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/TestPortAudioDevice.pas b/test/TestPortAudioDevice.pas index 3b6e1cd4..10c49034 100644 --- a/test/TestPortAudioDevice.pas +++ b/test/TestPortAudioDevice.pas @@ -35,7 +35,8 @@ program TestPortAudioDevice; {$ENDIF} uses - PortAudio in '../../src/lib/portaudio/portaudio.pas'; + SysUtils, + PortAudio in '../src/lib/portaudio/portaudio.pas'; const paDefaultApi = -1; @@ -107,17 +108,39 @@ begin writeln ('*** Test of Pa_Initialize and Pa_Terminate ***'); PaError := Pa_Initialize; if PaError = paNoError then - writeln ('Pa_Initialize: NoError') + writeln ('Pa_Initialize: No error') else writeln ('Pa_Initialize: Error No ', PaError); PaError := Pa_Terminate; if PaError = paNoError then - writeln ('Pa_Terminate: NoError') + writeln ('Pa_Terminate: No error') else writeln ('Pa_Terminate: Error No: ', PaError); writeln; + writeln ('*** Test of Pa_GetVersion and Pa_GetVersionText ***'); + PaError := Pa_Initialize; + writeln ('Pa_GetVersion: ', Pa_GetVersion); + writeln ('Pa_GetVersionText: ', Pa_GetVersionText); + PaError := Pa_Terminate; + writeln; + + writeln ('*** Test of Pa_GetErrorText ***'); + PaError := Pa_Initialize; + writeln ('paNoError (0): ', Pa_GetErrorText(PaError)); + writeln; + writeln ('Code Text'); + writeln ('------------------------------------'); + i := paNotInitialized; + repeat + writeln (i:6, ' ', Pa_GetErrorText(i)); + i := succ(i); + until SameText(Pa_GetErrorText(i), 'Invalid error code') or (i = paNotInitialized + 100); + writeln (i:6, ' ', Pa_GetErrorText(i)); + PaError := Pa_Terminate; + writeln; + writeln ('*** Test of GetPreferredApiIndex ***'); PaError := Pa_Initialize; paApiIndex := GetPreferredApiIndex(); -- cgit v1.2.3 From 1ce86c93531728a92db7972f901153de1814eac8 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sun, 7 Mar 2010 13:55:57 +0000 Subject: more tests. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2182 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/TestPortAudioDevice.pas | 118 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/TestPortAudioDevice.pas b/test/TestPortAudioDevice.pas index 10c49034..d77bff8f 100644 --- a/test/TestPortAudioDevice.pas +++ b/test/TestPortAudioDevice.pas @@ -36,6 +36,7 @@ program TestPortAudioDevice; uses SysUtils, + ctypes, PortAudio in '../src/lib/portaudio/portaudio.pas'; const @@ -63,7 +64,10 @@ var paApiInfo: PPaHostApiInfo; deviceIndex: TPaDeviceIndex; deviceInfo: PPaDeviceInfo; - + inputParameters: PPaStreamParameters; + outputParameters: PPaStreamParameters; + sampleRate: cdouble; + function GetPreferredApiIndex(): TPaHostApiIndex; var i: integer; @@ -119,13 +123,6 @@ begin writeln ('Pa_Terminate: Error No: ', PaError); writeln; - writeln ('*** Test of Pa_GetVersion and Pa_GetVersionText ***'); - PaError := Pa_Initialize; - writeln ('Pa_GetVersion: ', Pa_GetVersion); - writeln ('Pa_GetVersionText: ', Pa_GetVersionText); - PaError := Pa_Terminate; - writeln; - writeln ('*** Test of Pa_GetErrorText ***'); PaError := Pa_Initialize; writeln ('paNoError (0): ', Pa_GetErrorText(PaError)); @@ -141,6 +138,31 @@ begin PaError := Pa_Terminate; writeln; + writeln ('*** Test of Pa_GetVersion and Pa_GetVersionText ***'); + PaError := Pa_Initialize; + writeln ('Pa_GetVersion: ', Pa_GetVersion); + writeln ('Pa_GetVersionText: ', Pa_GetVersionText); + PaError := Pa_Terminate; + writeln; + + writeln ('*** Test of Pa_GetDeviceCount ***'); + PaError := Pa_Initialize; + writeln ('Pa_GetDeviceCount: ', Pa_GetDeviceCount); + PaError := Pa_Terminate; + writeln; + + writeln ('*** Test of Pa_GetDefaultInputDevice ***'); + PaError := Pa_Initialize; + writeln ('Pa_GetDefaultInputDevice: ', Pa_GetDefaultInputDevice); + PaError := Pa_Terminate; + writeln; + + writeln ('*** Test of Pa_GetDefaultOutputDevice ***'); + PaError := Pa_Initialize; + writeln ('Pa_GetDefaultOutputDevice: ', Pa_GetDefaultOutputDevice); + PaError := Pa_Terminate; + writeln; + writeln ('*** Test of GetPreferredApiIndex ***'); PaError := Pa_Initialize; paApiIndex := GetPreferredApiIndex(); @@ -178,7 +200,8 @@ begin writeln; writeln ('*** Test of Pa_GetDeviceInfo ***'); -// +// Note: the fields of deviceInfo can also be used without the '^'. +// deviceInfo.name works as well as deviceInfo^.name PaError := Pa_Initialize; paApiIndex := GetPreferredApiIndex(); paApiInfo := Pa_GetHostApiInfo(paApiIndex); @@ -195,10 +218,85 @@ begin writeln ('deviceInfo[', i, '].defaultLowOutputLatency: ', deviceInfo^.defaultLowOutputLatency); writeln ('deviceInfo[', i, '].defaultHighInputLatency: ', deviceInfo^.defaultHighInputLatency); writeln ('deviceInfo[', i, '].defaultHighOutputLatency: ', deviceInfo^.defaultHighOutputLatency); - writeln ('deviceInfo[', i, '].defaultSampleRate: ', deviceInfo^.defaultSampleRate:5:1); + writeln ('deviceInfo[', i, '].defaultSampleRate: ', deviceInfo^.defaultSampleRate:5:0); writeln; end; PaError := Pa_Terminate; + writeln ('*** Test of Pa_IsFormatSupported ***'); +// Note: the fields of deviceInfo can also be used without the '^'. +// deviceInfo.name works as well as deviceInfo^.name + PaError := Pa_Initialize; + paApiIndex := GetPreferredApiIndex(); + paApiInfo := Pa_GetHostApiInfo(paApiIndex); + for i:= 0 to paApiInfo^.deviceCount - 1 do + begin + deviceIndex := Pa_HostApiDeviceIndexToDeviceIndex(paApiIndex, i); + deviceInfo := Pa_GetDeviceInfo(deviceIndex); + writeln ('Device[', i, '] ', deviceInfo^.name, ':'); + New(inputParameters); + New(outputParameters); + if deviceInfo^.maxInputChannels > 0 then + begin + inputParameters^.device := deviceIndex; + inputParameters^.channelCount := deviceInfo^.maxInputChannels; + inputParameters^.sampleFormat := paInt16; + inputParameters^.suggestedLatency := deviceInfo^.defaultLowInputLatency; + inputParameters^.hostApiSpecificStreamInfo := nil; + outputParameters := nil; + end + else + begin + inputParameters := nil; + outputParameters^.device := deviceIndex; + outputParameters^.channelCount := deviceInfo^.maxOutputChannels; + outputParameters^.sampleFormat := paInt16; + outputParameters^.suggestedLatency := deviceInfo^.defaultLowOutputLatency; + outputParameters^.hostApiSpecificStreamInfo := nil; + end; + sampleRate := deviceInfo^.defaultSampleRate; + PaError := Pa_IsFormatSupported(inputParameters, outputParameters, sampleRate); + if PaError = paFormatIsSupported then + writeln ('Sample rate: ', sampleRate:5:0, ' : supported') + else + writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', Pa_GetErrorText(PaError)); +{ + try + sampleRate := 48000; + PaError := Pa_IsFormatSupported(inputParameters, outputParameters, sampleRate); + if PaError = paFormatIsSupported then + writeln ('Sample rate: ', sampleRate:5:0, ' : supported') + else + writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', PaError); + except + On EDivByZero do + begin + writeln ('Division by 0 error with sample rate ', sampleRate:5:0); + PaError := Pa_Terminate; + PaError := Pa_Initialize; + end; + end; + try + sampleRate := 90000; + PaError := Pa_IsFormatSupported(inputParameters, outputParameters, sampleRate); + if PaError = paFormatIsSupported then + writeln ('Sample rate: ', sampleRate:5:0, ' : supported') + else + writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', Pa_GetErrorText(PaError)); + except + On EDivByZero do + begin + writeln ('Division by 0 error with sample rate ', sampleRate:5:0); + PaError := Pa_Terminate; + PaError := Pa_Initialize; + end; + end; +} + Dispose(inputParameters); + Dispose(outputParameters); + end; + writeln; + PaError := Pa_Terminate; + writeln ('End: Test of Portaudio libs'); end. \ No newline at end of file -- cgit v1.2.3 From 4b0c20b7c18c0f185afb04da4c407c59a28f5efb Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sun, 7 Mar 2010 22:04:14 +0000 Subject: more portaudio tests added. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2183 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/TestPortAudioDevice.pas | 178 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 143 insertions(+), 35 deletions(-) (limited to 'test') diff --git a/test/TestPortAudioDevice.pas b/test/TestPortAudioDevice.pas index d77bff8f..0747e412 100644 --- a/test/TestPortAudioDevice.pas +++ b/test/TestPortAudioDevice.pas @@ -42,7 +42,6 @@ uses const paDefaultApi = -1; -const ApiPreferenceOrder: {$IF Defined(MSWINDOWS)} // Note1: Portmixer has no mixer support for paASIO and paWASAPI at the moment @@ -57,8 +56,23 @@ const array[0..0] of TPaHostApiTypeId = ( paDefaultApi ); {$IFEND} + standardSampleRates: array[1..13] of cdouble = + ( 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, + 22050.0, 24000.0, 32000.0, 44100.0, 48000.0, + 88200.0, 96000.0, 192000.0 + ); + + SampleFormat: array[1..8] of culong = + (paFloat32, paInt32, paInt24, paInt16, paInt8, paUInt8, + paCustomFormat, paNonInterleaved + ); + SampleFormatName: array[1..8] of string = + ('paFloat32', 'paInt32', 'paInt24', 'paInt16', 'paInt8', 'paUInt8', + 'paCustomFormat', 'paNonInterleaved' + ); + var - i: integer; + i, j: integer; PaError: TPaError; paApiIndex: TPaHostApiIndex; paApiInfo: PPaHostApiInfo; @@ -67,7 +81,12 @@ var inputParameters: PPaStreamParameters; outputParameters: PPaStreamParameters; sampleRate: cdouble; - + stream: PPaStream; + framesPerBuffer: culong; + streamFlags: TPaStreamFlags; + streamCallback: PPaStreamCallback; + userData: Pointer; + function GetPreferredApiIndex(): TPaHostApiIndex; var i: integer; @@ -105,6 +124,35 @@ begin end; end; +function DummyCallback(input: pointer; output: pointer; frameCount: longword; + timeInfo: PPaStreamCallbackTimeInfo; statusFlags: TPaStreamCallbackFlags; + userData: pointer): integer; cdecl; +begin + result := paContinue; +end; + +function MicrophoneCallback(input: pointer; output: pointer; frameCount: longword; + timeInfo: PPaStreamCallbackTimeInfo; statusFlags: TPaStreamCallbackFlags; + inputDevice: pointer): integer; cdecl; +begin +// AudioInputProcessor.HandleMicrophoneData(input, frameCount*4, inputDevice); + result := paContinue; +end; + +function PortaudioAudioCallback(input: pointer; output: pointer; frameCount: longword; + timeInfo: PPaStreamCallbackTimeInfo; statusFlags: TPaStreamCallbackFlags; + userData: pointer): integer; cdecl; +{var + Engine: TAudioPlayback_Portaudio; +}begin +{ Engine := TAudioPlayback_Portaudio(userData); + // update latency + Engine.Latency := timeInfo.outputBufferDacTime - timeInfo.currentTime; + // call superclass callback + Engine.AudioCallback(output, frameCount * Engine.FormatInfo.FrameSize); +} Result := paContinue; +end; + begin writeln ('Start: Test of Portaudio libs'); writeln; @@ -214,18 +262,16 @@ begin writeln ('deviceInfo[', i, '].hostApi: ', deviceInfo^.hostApi); writeln ('deviceInfo[', i, '].maxInputChannels: ', deviceInfo^.maxInputChannels); writeln ('deviceInfo[', i, '].maxOutputChannels: ', deviceInfo^.maxOutputChannels); - writeln ('deviceInfo[', i, '].defaultLowInputLatency: ', deviceInfo^.defaultLowInputLatency); - writeln ('deviceInfo[', i, '].defaultLowOutputLatency: ', deviceInfo^.defaultLowOutputLatency); - writeln ('deviceInfo[', i, '].defaultHighInputLatency: ', deviceInfo^.defaultHighInputLatency); - writeln ('deviceInfo[', i, '].defaultHighOutputLatency: ', deviceInfo^.defaultHighOutputLatency); + writeln ('deviceInfo[', i, '].defaultLowInputLatency: ', deviceInfo^.defaultLowInputLatency:6:4); + writeln ('deviceInfo[', i, '].defaultLowOutputLatency: ', deviceInfo^.defaultLowOutputLatency:6:4); + writeln ('deviceInfo[', i, '].defaultHighInputLatency: ', deviceInfo^.defaultHighInputLatency:6:4); + writeln ('deviceInfo[', i, '].defaultHighOutputLatency: ', deviceInfo^.defaultHighOutputLatency:6:4); writeln ('deviceInfo[', i, '].defaultSampleRate: ', deviceInfo^.defaultSampleRate:5:0); writeln; end; PaError := Pa_Terminate; writeln ('*** Test of Pa_IsFormatSupported ***'); -// Note: the fields of deviceInfo can also be used without the '^'. -// deviceInfo.name works as well as deviceInfo^.name PaError := Pa_Initialize; paApiIndex := GetPreferredApiIndex(); paApiInfo := Pa_GetHostApiInfo(paApiIndex); @@ -236,12 +282,13 @@ begin writeln ('Device[', i, '] ', deviceInfo^.name, ':'); New(inputParameters); New(outputParameters); + if deviceInfo^.maxInputChannels > 0 then begin inputParameters^.device := deviceIndex; inputParameters^.channelCount := deviceInfo^.maxInputChannels; inputParameters^.sampleFormat := paInt16; - inputParameters^.suggestedLatency := deviceInfo^.defaultLowInputLatency; + inputParameters^.suggestedLatency := 0; inputParameters^.hostApiSpecificStreamInfo := nil; outputParameters := nil; end @@ -251,52 +298,113 @@ begin outputParameters^.device := deviceIndex; outputParameters^.channelCount := deviceInfo^.maxOutputChannels; outputParameters^.sampleFormat := paInt16; - outputParameters^.suggestedLatency := deviceInfo^.defaultLowOutputLatency; + outputParameters^.suggestedLatency := 0; outputParameters^.hostApiSpecificStreamInfo := nil; end; + sampleRate := deviceInfo^.defaultSampleRate; PaError := Pa_IsFormatSupported(inputParameters, outputParameters, sampleRate); if PaError = paFormatIsSupported then writeln ('Sample rate: ', sampleRate:5:0, ' : supported') else writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', Pa_GetErrorText(PaError)); -{ - try - sampleRate := 48000; + +{$IF not Defined(DARWIN)} // as long as the darwin bug is not resolved + for j := low(standardSampleRates) to high(standardSampleRates) do + begin + sampleRate := standardSampleRates[j]; PaError := Pa_IsFormatSupported(inputParameters, outputParameters, sampleRate); if PaError = paFormatIsSupported then writeln ('Sample rate: ', sampleRate:5:0, ' : supported') else writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', PaError); - except - On EDivByZero do - begin - writeln ('Division by 0 error with sample rate ', sampleRate:5:0); - PaError := Pa_Terminate; - PaError := Pa_Initialize; - end; end; - try - sampleRate := 90000; - PaError := Pa_IsFormatSupported(inputParameters, outputParameters, sampleRate); +{$IFEND} + + writeln; + for j := low(SampleFormat) to high(SampleFormat) do + begin + if inputParameters <> nil then + inputParameters^.sampleFormat := SampleFormat[j] + else + outputParameters^.sampleFormat := SampleFormat[j]; + PaError := Pa_IsFormatSupported(inputParameters, outputParameters, sampleRate); if PaError = paFormatIsSupported then - writeln ('Sample rate: ', sampleRate:5:0, ' : supported') + writeln ('Sample Format ', SampleFormatName[j], ': supported') else - writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', Pa_GetErrorText(PaError)); - except - On EDivByZero do - begin - writeln ('Division by 0 error with sample rate ', sampleRate:5:0); - PaError := Pa_Terminate; - PaError := Pa_Initialize; - end; + writeln ('Sample Format ', SampleFormatName[j], ': ', Pa_GetErrorText(PaError)); end; -} + Dispose(inputParameters); Dispose(outputParameters); + writeln; end; - writeln; PaError := Pa_Terminate; + writeln ('*** Test of Pa_OpenStream and Pa_CloseStream ***'); + PaError := Pa_Initialize; + paApiIndex := GetPreferredApiIndex(); + paApiInfo := Pa_GetHostApiInfo(paApiIndex); + for i:= 0 to paApiInfo^.deviceCount - 1 do + begin + deviceIndex := Pa_HostApiDeviceIndexToDeviceIndex(paApiIndex, i); + deviceInfo := Pa_GetDeviceInfo(deviceIndex); + writeln ('Device[', i, '] ', deviceInfo^.name, ':'); + New(inputParameters); + New(outputParameters); + New(stream); + New(userData); + if deviceInfo^.maxInputChannels > 0 then + begin + inputParameters^.device := deviceIndex; + inputParameters^.channelCount := deviceInfo^.maxInputChannels; + inputParameters^.sampleFormat := paInt16; + inputParameters^.suggestedLatency := 0; + inputParameters^.hostApiSpecificStreamInfo := nil; + outputParameters := nil; + end + else + begin + inputParameters := nil; + outputParameters^.device := deviceIndex; + outputParameters^.channelCount := deviceInfo^.maxOutputChannels; + outputParameters^.sampleFormat := paInt16; + outputParameters^.suggestedLatency := 0; + outputParameters^.hostApiSpecificStreamInfo := nil; + end; + + sampleRate := deviceInfo^.defaultSampleRate; + framesPerBuffer := paFramesPerBufferUnspecified; + streamFlags := paNoFlag; + streamCallback := @DummyCallback; + + PaError := Pa_OpenStream( + stream, + inputParameters, + outputParameters, + sampleRate, + framesPerBuffer, + streamFlags, + streamCallback, + userData + ); + if PaError = paNoError then + writeln ('Pa_OpenStream: success') + else + writeln ('Pa_OpenStream: ', Pa_GetErrorText(PaError)); + + PaError := Pa_CloseStream(stream); + if PaError = paNoError then + writeln ('Pa_CloseStream: success') + else + writeln ('Pa_CloseStream: ', Pa_GetErrorText(PaError)); + + Dispose(inputParameters); + Dispose(outputParameters); + + writeln; + end; + PaError := Pa_Terminate; + writeln ('End: Test of Portaudio libs'); end. \ No newline at end of file -- cgit v1.2.3 From 2a25aa524f166365813bcfd62635817a7f320a96 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Mon, 8 Mar 2010 12:26:22 +0000 Subject: more tests and floating point exception problem resolved on darwin through setting the exception mask. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2184 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/TestPortAudioDevice.pas | 80 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/TestPortAudioDevice.pas b/test/TestPortAudioDevice.pas index 0747e412..ff5b70bc 100644 --- a/test/TestPortAudioDevice.pas +++ b/test/TestPortAudioDevice.pas @@ -37,6 +37,9 @@ program TestPortAudioDevice; uses SysUtils, ctypes, +{$IF Defined(DARWIN)} // for setting the floating point exception mask + math, +{$IFEND} PortAudio in '../src/lib/portaudio/portaudio.pas'; const @@ -124,18 +127,70 @@ begin end; end; -function DummyCallback(input: pointer; output: pointer; frameCount: longword; - timeInfo: PPaStreamCallbackTimeInfo; statusFlags: TPaStreamCallbackFlags; - userData: pointer): integer; cdecl; +{ +type + TAudioSampleFormat = ( + asfU8, asfS8, // unsigned/signed 8 bits + asfU16LSB, asfS16LSB, // unsigned/signed 16 bits (endianness: LSB) + asfU16MSB, asfS16MSB, // unsigned/signed 16 bits (endianness: MSB) + asfU16, asfS16, // unsigned/signed 16 bits (endianness: System) + asfS32, // signed 32 bits (endianness: System) + asfFloat, // float + asfDouble // double + ); + TAudioFormatInfo = ; + TAudioInputDevice = record + AudioFormat: TAudioFormatInfo; // capture format info (e.g. 44.1kHz SInt16 stereo) + CaptureChannel: array of TCaptureBuffer; // sound-buffer references used for mono or stereo channel's capture data + end; + +procedure HandleMicrophoneData(Buffer: PByteArray; Size: integer; InputDevice: TAudioInputDevice); +var + MultiChannelBuffer: PByteArray; // buffer handled as array of bytes (offset relative to channel) + SingleChannelBuffer: PByteArray; // temporary buffer for new samples per channel + SingleChannelBufferSize: integer; + ChannelIndex: integer; + CaptureChannel: TCaptureBuffer; + AudioFormat: TAudioFormatInfo; + SampleSize: integer; + SamplesPerChannel: integer; + i: integer; begin - result := paContinue; -end; + AudioFormat := InputDevice.AudioFormat; + SampleSize := AudioSampleSize[AudioFormat.Format]; + SamplesPerChannel := Size div AudioFormat.FrameSize; + + SingleChannelBufferSize := SamplesPerChannel * SampleSize; + GetMem(SingleChannelBuffer, SingleChannelBufferSize); + + // process channels + for ChannelIndex := 0 to High(InputDevice.CaptureChannel) do + begin + CaptureChannel := InputDevice.CaptureChannel[ChannelIndex]; + // check if a capture buffer was assigned, otherwise there is nothing to do + if (CaptureChannel <> nil) then + begin + // set offset according to channel index + MultiChannelBuffer := @Buffer[ChannelIndex * SampleSize]; + // separate channel-data from interleaved multi-channel (e.g. stereo) data + for i := 0 to SamplesPerChannel-1 do + begin + Move(MultiChannelBuffer[i*AudioFormat.FrameSize], + SingleChannelBuffer[i*SampleSize], + SampleSize); + end; + CaptureChannel.ProcessNewBuffer(SingleChannelBuffer, SingleChannelBufferSize); + end; + end; + FreeMem(SingleChannelBuffer); +end; +} function MicrophoneCallback(input: pointer; output: pointer; frameCount: longword; timeInfo: PPaStreamCallbackTimeInfo; statusFlags: TPaStreamCallbackFlags; inputDevice: pointer): integer; cdecl; begin -// AudioInputProcessor.HandleMicrophoneData(input, frameCount*4, inputDevice); +// HandleMicrophoneData(input, frameCount*4, inputDevice); result := paContinue; end; @@ -309,7 +364,10 @@ begin else writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', Pa_GetErrorText(PaError)); -{$IF not Defined(DARWIN)} // as long as the darwin bug is not resolved +{$IF Defined(DARWIN)} // floating point exceptions are raised. Therefore, set the exception mask. + SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, + exOverflow, exUnderflow, exPrecision]); +{$IFEND} for j := low(standardSampleRates) to high(standardSampleRates) do begin sampleRate := standardSampleRates[j]; @@ -319,7 +377,6 @@ begin else writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', PaError); end; -{$IFEND} writeln; for j := low(SampleFormat) to high(SampleFormat) do @@ -352,8 +409,6 @@ begin writeln ('Device[', i, '] ', deviceInfo^.name, ':'); New(inputParameters); New(outputParameters); - New(stream); - New(userData); if deviceInfo^.maxInputChannels > 0 then begin inputParameters^.device := deviceIndex; @@ -376,7 +431,8 @@ begin sampleRate := deviceInfo^.defaultSampleRate; framesPerBuffer := paFramesPerBufferUnspecified; streamFlags := paNoFlag; - streamCallback := @DummyCallback; + streamCallback := nil; + userData := nil; PaError := Pa_OpenStream( stream, @@ -388,7 +444,7 @@ begin streamCallback, userData ); - if PaError = paNoError then + if (PaError = paNoError) and (stream <> nil) then writeln ('Pa_OpenStream: success') else writeln ('Pa_OpenStream: ', Pa_GetErrorText(PaError)); -- cgit v1.2.3 From d2e8b131a46cb875cc200868cf06fd5a7d7c7b08 Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Mon, 8 Mar 2010 17:06:15 +0000 Subject: set only the exception mask as necessary. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2185 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/TestPortAudioDevice.pas | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/TestPortAudioDevice.pas b/test/TestPortAudioDevice.pas index ff5b70bc..1308858f 100644 --- a/test/TestPortAudioDevice.pas +++ b/test/TestPortAudioDevice.pas @@ -365,8 +365,7 @@ begin writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', Pa_GetErrorText(PaError)); {$IF Defined(DARWIN)} // floating point exceptions are raised. Therefore, set the exception mask. - SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, - exOverflow, exUnderflow, exPrecision]); + SetExceptionMask([exZeroDivide, exPrecision]); {$IFEND} for j := low(standardSampleRates) to high(standardSampleRates) do begin -- cgit v1.2.3 From 96ad83476a7226bdc92f8ebfca3030d49e5123a1 Mon Sep 17 00:00:00 2001 From: tobigun Date: Sun, 25 Apr 2010 19:58:34 +0000 Subject: a value of 0 for suggestedLatency is invalid git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2310 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/TestPortAudioDevice.pas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/TestPortAudioDevice.pas b/test/TestPortAudioDevice.pas index 1308858f..1b3c9e7e 100644 --- a/test/TestPortAudioDevice.pas +++ b/test/TestPortAudioDevice.pas @@ -413,7 +413,7 @@ begin inputParameters^.device := deviceIndex; inputParameters^.channelCount := deviceInfo^.maxInputChannels; inputParameters^.sampleFormat := paInt16; - inputParameters^.suggestedLatency := 0; + inputParameters^.suggestedLatency := deviceInfo.defaultLowInputLatency; inputParameters^.hostApiSpecificStreamInfo := nil; outputParameters := nil; end @@ -423,7 +423,7 @@ begin outputParameters^.device := deviceIndex; outputParameters^.channelCount := deviceInfo^.maxOutputChannels; outputParameters^.sampleFormat := paInt16; - outputParameters^.suggestedLatency := 0; + outputParameters^.suggestedLatency := deviceInfo.defaultLowOutputLatency; outputParameters^.hostApiSpecificStreamInfo := nil; end; -- cgit v1.2.3 From 074d15b66dc7a585c28af26ff1df041349198b8c Mon Sep 17 00:00:00 2001 From: tobigun Date: Tue, 27 Apr 2010 18:56:32 +0000 Subject: - callback stream test added - input latency changed to defaultHighInputLatency git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2312 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/TestPortAudioDevice.pas | 165 ++++++++++++++++++++++++++++++------------- 1 file changed, 114 insertions(+), 51 deletions(-) (limited to 'test') diff --git a/test/TestPortAudioDevice.pas b/test/TestPortAudioDevice.pas index 1b3c9e7e..ba394383 100644 --- a/test/TestPortAudioDevice.pas +++ b/test/TestPortAudioDevice.pas @@ -37,9 +37,8 @@ program TestPortAudioDevice; uses SysUtils, ctypes, -{$IF Defined(DARWIN)} // for setting the floating point exception mask + crt, math, -{$IFEND} PortAudio in '../src/lib/portaudio/portaudio.pas'; const @@ -88,8 +87,11 @@ var framesPerBuffer: culong; streamFlags: TPaStreamFlags; streamCallback: PPaStreamCallback; + callbackStartTime: TDateTime; + callbackWorks: boolean; userData: Pointer; + function GetPreferredApiIndex(): TPaHostApiIndex; var i: integer; @@ -186,32 +188,9 @@ begin FreeMem(SingleChannelBuffer); end; } -function MicrophoneCallback(input: pointer; output: pointer; frameCount: longword; - timeInfo: PPaStreamCallbackTimeInfo; statusFlags: TPaStreamCallbackFlags; - inputDevice: pointer): integer; cdecl; -begin -// HandleMicrophoneData(input, frameCount*4, inputDevice); - result := paContinue; -end; - -function PortaudioAudioCallback(input: pointer; output: pointer; frameCount: longword; - timeInfo: PPaStreamCallbackTimeInfo; statusFlags: TPaStreamCallbackFlags; - userData: pointer): integer; cdecl; -{var - Engine: TAudioPlayback_Portaudio; -}begin -{ Engine := TAudioPlayback_Portaudio(userData); - // update latency - Engine.Latency := timeInfo.outputBufferDacTime - timeInfo.currentTime; - // call superclass callback - Engine.AudioCallback(output, frameCount * Engine.FormatInfo.FrameSize); -} Result := paContinue; -end; +procedure TestInitTerminate(); begin - writeln ('Start: Test of Portaudio libs'); - writeln; - writeln ('*** Test of Pa_Initialize and Pa_Terminate ***'); PaError := Pa_Initialize; if PaError = paNoError then @@ -225,7 +204,10 @@ begin else writeln ('Pa_Terminate: Error No: ', PaError); writeln; - +end; + +procedure TestErrorText(); +begin writeln ('*** Test of Pa_GetErrorText ***'); PaError := Pa_Initialize; writeln ('paNoError (0): ', Pa_GetErrorText(PaError)); @@ -240,32 +222,20 @@ begin writeln (i:6, ' ', Pa_GetErrorText(i)); PaError := Pa_Terminate; writeln; +end; +procedure TestVersion(); +begin writeln ('*** Test of Pa_GetVersion and Pa_GetVersionText ***'); PaError := Pa_Initialize; writeln ('Pa_GetVersion: ', Pa_GetVersion); writeln ('Pa_GetVersionText: ', Pa_GetVersionText); PaError := Pa_Terminate; writeln; +end; - writeln ('*** Test of Pa_GetDeviceCount ***'); - PaError := Pa_Initialize; - writeln ('Pa_GetDeviceCount: ', Pa_GetDeviceCount); - PaError := Pa_Terminate; - writeln; - - writeln ('*** Test of Pa_GetDefaultInputDevice ***'); - PaError := Pa_Initialize; - writeln ('Pa_GetDefaultInputDevice: ', Pa_GetDefaultInputDevice); - PaError := Pa_Terminate; - writeln; - - writeln ('*** Test of Pa_GetDefaultOutputDevice ***'); - PaError := Pa_Initialize; - writeln ('Pa_GetDefaultOutputDevice: ', Pa_GetDefaultOutputDevice); - PaError := Pa_Terminate; - writeln; - +procedure TestApiInfo(); +begin writeln ('*** Test of GetPreferredApiIndex ***'); PaError := Pa_Initialize; paApiIndex := GetPreferredApiIndex(); @@ -301,6 +271,27 @@ begin end; PaError := Pa_Terminate; writeln; +end; + +procedure TestDeviceInfo(); +begin + writeln ('*** Test of Pa_GetDeviceCount ***'); + PaError := Pa_Initialize; + writeln ('Pa_GetDeviceCount: ', Pa_GetDeviceCount); + PaError := Pa_Terminate; + writeln; + + writeln ('*** Test of Pa_GetDefaultInputDevice ***'); + PaError := Pa_Initialize; + writeln ('Pa_GetDefaultInputDevice: ', Pa_GetDefaultInputDevice); + PaError := Pa_Terminate; + writeln; + + writeln ('*** Test of Pa_GetDefaultOutputDevice ***'); + PaError := Pa_Initialize; + writeln ('Pa_GetDefaultOutputDevice: ', Pa_GetDefaultOutputDevice); + PaError := Pa_Terminate; + writeln; writeln ('*** Test of Pa_GetDeviceInfo ***'); // Note: the fields of deviceInfo can also be used without the '^'. @@ -325,7 +316,10 @@ begin writeln; end; PaError := Pa_Terminate; +end; +procedure TestFormatInfo(); +begin writeln ('*** Test of Pa_IsFormatSupported ***'); PaError := Pa_Initialize; paApiIndex := GetPreferredApiIndex(); @@ -364,9 +358,6 @@ begin else writeln ('Sample rate: ', sampleRate:5:0, ' : Error: ', Pa_GetErrorText(PaError)); -{$IF Defined(DARWIN)} // floating point exceptions are raised. Therefore, set the exception mask. - SetExceptionMask([exZeroDivide, exPrecision]); -{$IFEND} for j := low(standardSampleRates) to high(standardSampleRates) do begin sampleRate := standardSampleRates[j]; @@ -396,7 +387,26 @@ begin writeln; end; PaError := Pa_Terminate; +end; +function AudioCallback(input: pointer; output: pointer; frameCount: culong; + timeInfo: PPaStreamCallbackTimeInfo; statusFlags: TPaStreamCallbackFlags; + inputDevice: pointer): cint; cdecl; +var + duration: real; +begin + duration := (Now() - callbackStartTime) * 24 * 3600; + if (duration < 2.0) then + result := paContinue + else + begin + callbackWorks := true; + result := paComplete; + end; +end; + +procedure TestStreams(); +begin writeln ('*** Test of Pa_OpenStream and Pa_CloseStream ***'); PaError := Pa_Initialize; paApiIndex := GetPreferredApiIndex(); @@ -413,7 +423,7 @@ begin inputParameters^.device := deviceIndex; inputParameters^.channelCount := deviceInfo^.maxInputChannels; inputParameters^.sampleFormat := paInt16; - inputParameters^.suggestedLatency := deviceInfo.defaultLowInputLatency; + inputParameters^.suggestedLatency := deviceInfo.defaultHighInputLatency; inputParameters^.hostApiSpecificStreamInfo := nil; outputParameters := nil; end @@ -430,9 +440,9 @@ begin sampleRate := deviceInfo^.defaultSampleRate; framesPerBuffer := paFramesPerBufferUnspecified; streamFlags := paNoFlag; - streamCallback := nil; + streamCallback := @AudioCallback; userData := nil; - + PaError := Pa_OpenStream( stream, inputParameters, @@ -448,6 +458,43 @@ begin else writeln ('Pa_OpenStream: ', Pa_GetErrorText(PaError)); + if (PaError = paNoError) and (stream <> nil) then + begin + callbackStartTime := Now(); + + PaError := Pa_StartStream(stream); + if (PaError = paNoError) then + writeln ('Pa_StartStream: success') + else + writeln ('Pa_StartStream: ', Pa_GetErrorText(PaError)); + + callbackWorks := false; + + // wait twice the time a successful callback would need for termination + writeln('Wait for callback'); + delay(4000); + + if (callbackWorks and (Pa_IsStreamStopped(stream) = 0)) then + begin + writeln ('Success: Device works'); + PaError := Pa_StopStream(stream); + if (PaError = paNoError) then + writeln ('Pa_StopStream: success') + else + writeln ('Pa_StopStream: ', Pa_GetErrorText(PaError)); + end + else + begin + writeln ('Error: Non working device'); + PaError := Pa_AbortStream(stream); + if (PaError = paNoError) then + writeln ('Pa_AbortStream: success') + else + writeln ('Pa_AbortStream: ', Pa_GetErrorText(PaError)); + + end; + end; + PaError := Pa_CloseStream(stream); if PaError = paNoError then writeln ('Pa_CloseStream: success') @@ -460,6 +507,22 @@ begin writeln; end; PaError := Pa_Terminate; +end; + +begin + // floating point exceptions are raised. Therefore, set the exception mask. + SetExceptionMask([exZeroDivide, exPrecision]); + + writeln ('Start: Test of Portaudio libs'); + writeln; + + //TestInitTerminate(); + //TestErrorText(); + //TestVersion(); + //TestApiInfo(); + //TestDeviceInfo(); + //TestFormatInfo(); + TestStreams(); writeln ('End: Test of Portaudio libs'); end. \ No newline at end of file -- cgit v1.2.3 From 922a96ef136b10d2ee77129cb63752dc389a74ae Mon Sep 17 00:00:00 2001 From: k-m_schindler Date: Sun, 16 May 2010 22:51:29 +0000 Subject: Test for sign algorithm in libavutil/libavcodec. git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/trunk@2379 b956fd51-792f-4845-bead-9b4dfca2ff2c --- test/TestSignAlgorithm.pas | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/TestSignAlgorithm.pas (limited to 'test') diff --git a/test/TestSignAlgorithm.pas b/test/TestSignAlgorithm.pas new file mode 100644 index 00000000..915e5681 --- /dev/null +++ b/test/TestSignAlgorithm.pas @@ -0,0 +1,58 @@ +program TestSignAlgorithm; + +uses + sysutils; + +const + a1 = 2; + a2 = 1; + a3 = 0; + a4 = -1; + a5 = -2; + +var + index, number: longint; + +begin + writeln; + writeln ('This tests the arithmetic procedure used in libavutil and libavcodec.'); + writeln ('positive numbers should give 1, negative numbers -1.'); + writeln ('-17: ', not((-17 shr 30) and $00000002) + 2); + writeln ('-16: ', not((-16 shr 30) and $00000002) + 2); + writeln ('-15: ', not((-15 shr 30) and $00000002) + 2); + writeln (' -3: ', not(( -3 shr 30) and $00000002) + 2); + writeln (' -2: ', not(( -2 shr 30) and $00000002) + 2); + writeln (' -1: ', not(( -1 shr 30) and $00000002) + 2); + writeln (' 0: ', not(( 0 shr 30) and $00000002) + 2); + writeln (' 1: ', not(( 1 shr 30) and $00000002) + 2); + writeln (' 2: ', not(( 2 shr 30) and $00000002) + 2); + writeln (' 3: ', not(( 3 shr 30) and $00000002) + 2); + writeln (' 8: ', not(( 8 shr 30) and $00000002) + 2); + writeln ('MaxInt: ', MaxInt:12, ' ', IntToHex(MaxInt,8), ' ', not((MaxInt shr 30) and $00000002) + 2); + writeln ('MaxLongint: ', MaxLongint:12, ' ', IntToHex(MaxLongint,8), ' ', not((MaxLongint shr 30) and $00000002) + 2); + writeln ('MinInt: ', -MaxInt - 1:12, ' ', IntToHex(-MaxInt - 1,8), ' ', not(((-MaxInt - 1) shr 30) and $00000002) + 2); + writeln ('MinLongInt: ', -MaxLongint - 1:12, ' ', IntToHex(-MaxLongint - 1,8), ' ', not(((-MaxLongint - 1) shr 30) and $00000002) + 2); + writeln (a1, ' ', IntToHex(a1,8) , ' ', not((a1 shr 30) and $00000002) + 2); + writeln (a2, ' ', IntToHex(a2,8) , ' ', not((a2 shr 30) and $00000002) + 2); + writeln (a3, ' ', IntToHex(a3,8) , ' ', not((a3 shr 30) and $00000002) + 2); + writeln (a4, ' ', IntToHex(a4,8) , ' ', not((a4 shr 30) and $00000002) + 2); + writeln (a5, ' ', IntToHex(a5,8) , ' ', not((a5 shr 30) and $00000002) + 2); + writeln; + writeln ('Hit RETURN for more positive numbers. The last one overflows and becomes negative.'); + readln; + number := 1; + for index := 1 to 32 do + begin + writeln (index:2, ': ', number:11, ' ', IntToHex(number shr 30 ,8):10, ' ', not((number shr 30) and $00000002) + 2); + number := number * 2; + end; + writeln; + writeln ('Hit RETURN for more positive numbers.'); + readln; + number := -1; + for index := 1 to 32 do + begin + writeln (index:2, ': ', number:11, ' ', IntToHex(number shr 30 ,8):10, ' ', not((number shr 30) and $00000002) + 2); + number := number * 2; + end; +end. \ No newline at end of file -- cgit v1.2.3