we can use "sceAudioSetFrequency" to change AudioF

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
cooleyes
Posts: 123
Joined: Thu May 18, 2006 3:30 pm

we can use "sceAudioSetFrequency" to change AudioF

Post by cooleyes »

as we all know, we can use sceAudioOutputBlocking to play 16bit PCM data.

but all homebrew just support 44100Hz samplerate.

I browse moonlight's "PSP PRX Libraries Documentation Project",

and find out a function "sceAudioSetFrequency" in audio.prx , sceAudio_driver lib.

it can change the audio device's Frequency.

SceInt32 sceAudioSetFrequency(SceInt32 frequency); //frequency=44100 or 48000, if success it will return 0

it can setFrequency to 44100Hz or 48000Hz

sceAudio_driver.S

Code: Select all

	.set noreorder

#include "pspimport.s"

#ifdef F_sceAudio_driver_0000
	IMPORT_START	"sceAudio_driver",0x00010000
#endif

#ifdef F_sceAudio_driver_0001
	IMPORT_FUNC	"sceAudio_driver",0x80F1F7E0,sceAudioInit
#endif

#ifdef F_sceAudio_driver_0002 
	IMPORT_FUNC	"sceAudio_driver",0x210567F7,sceAudioEnd
#endif

#ifdef F_sceAudio_driver_0003 
	IMPORT_FUNC	"sceAudio_driver",0xA2BEAA6C,sceAudioSetFrequency 
#endif

#ifdef F_sceAudio_driver_0004
	IMPORT_FUNC	"sceAudio_driver",0xB61595C0,sceAudioLoopbackTest 
#endif

#ifdef F_sceAudio_driver_0005
	IMPORT_FUNC	"sceAudio_driver",0x927AC32B,sceAudioSetVolumeOffset 
#endif

#ifdef F_sceAudio_driver_0006
	IMPORT_FUNC	"sceAudio_driver",0x8C1009B2,sceAudioOutput 
#endif

#ifdef F_sceAudio_driver_0007
	IMPORT_FUNC	"sceAudio_driver",0x136CAF51,sceAudioOutputBlocking 
#endif

#ifdef F_sceAudio_driver_0008
	IMPORT_FUNC	"sceAudio_driver",0xE2D56B2D,sceAudioOutputPanned 
#endif

#ifdef F_sceAudio_driver_0009
	IMPORT_FUNC	"sceAudio_driver",0x13F592BC,sceAudioOutputPannedBlocking 
#endif

#ifdef F_sceAudio_driver_0010
	IMPORT_FUNC	"sceAudio_driver",0x5EC81C55,sceAudioChReserve 
#endif

#ifdef F_sceAudio_driver_0011
	IMPORT_FUNC	"sceAudio_driver",0x41EFADE7,sceAudioOneshotOutput 
#endif

#ifdef F_sceAudio_driver_0012
	IMPORT_FUNC	"sceAudio_driver",0x6FC46853,sceAudioChRelease 
#endif

#ifdef F_sceAudio_driver_0013
	IMPORT_FUNC	"sceAudio_driver",0xB011922F,sceAudio_driver_B011922F 
#endif

#ifdef F_sceAudio_driver_0014
	IMPORT_FUNC	"sceAudio_driver",0xCB2E439E,sceAudioSetChannelDataLen 
#endif

#ifdef F_sceAudio_driver_0015
	IMPORT_FUNC	"sceAudio_driver",0x95FD0C2D,sceAudioChangeChannelConfig 
#endif

#ifdef F_sceAudio_driver_0016
	IMPORT_FUNC	"sceAudio_driver",0xB7E1D8E7,sceAudioChangeChannelVolume 
#endif

#ifdef F_sceAudio_driver_0017
	IMPORT_FUNC	"sceAudio_driver",0x38553111,sceAudio_driver_38553111 
#endif

#ifdef F_sceAudio_driver_0018
	IMPORT_FUNC	"sceAudio_driver",0x5C37C0AE,sceAudio_driver_5C37C0AE 
#endif

#ifdef F_sceAudio_driver_0019
	IMPORT_FUNC	"sceAudio_driver",0xE0727056,sceAudio_driver_E0727056 
#endif

#ifdef F_sceAudio_driver_0020
	IMPORT_FUNC	"sceAudio_driver",0x086E5895,sceAudioInputBlocking 
#endif

#ifdef F_sceAudio_driver_0021
	IMPORT_FUNC	"sceAudio_driver",0x6D4BEC68,sceAudioInput 
#endif

#ifdef F_sceAudio_driver_0022
	IMPORT_FUNC	"sceAudio_driver",0xA708C6A6,sceAudioGetInputLength 
#endif

#ifdef F_sceAudio_driver_0023
	IMPORT_FUNC	"sceAudio_driver",0x87B2E651,sceAudioWaitInputEnd 
#endif

#ifdef F_sceAudio_driver_0024
	IMPORT_FUNC	"sceAudio_driver",0x7DE61688,sceAudioInputInit 
#endif

#ifdef F_sceAudio_driver_0025
	IMPORT_FUNC	"sceAudio_driver",0xE926D3FB,sceAudioInputInitEx 
#endif

#ifdef F_sceAudio_driver_0026
	IMPORT_FUNC	"sceAudio_driver",0xA633048E,sceAudioPollInputEnd 
#endif

#ifdef F_sceAudio_driver_0027
	IMPORT_FUNC	"sceAudio_driver",0xE9D97901,sceAudioGetChannelRestLen 
#endif
pspaudiodriver.h

Code: Select all

/*
 * pspaudiodriver.h - Prototypes for the sceAudio_driver library.
 *
 * Copyright &#40;c&#41; 2007 cooleyes <[email protected]>
 */
#ifndef __SCEAUDIODRIVER_H__
#define __SCEAUDIODRIVER_H__

#include <psptypes.h>

#ifdef __cplusplus
extern "C" &#123;
#endif

SceInt32 sceAudioSetFrequency&#40;SceInt32 frequency&#41;;

#ifdef __cplusplus
&#125;
#endif
SilverSpring
Posts: 110
Joined: Tue Feb 27, 2007 9:43 pm
Contact:

Post by SilverSpring »

int sceClockgenAudioClkSetFreq(int freq); // freq can be 44100 or 48000

Dont know if same outcome??

EDIT:

Ok, I just checked, sceAudioSetFrequency passes freq to sceClockgenAudioClkSetFreq to set the freq, but it also passes freq to sceCodecSetFrequency as well.
Mihawk
Posts: 29
Joined: Tue Apr 03, 2007 2:04 am

Post by Mihawk »

Nice, could be usefull.
But is it not possible to use lower frequencies, like 22.05 or 24kHz? or are only those two (44.1 and 48kHz) valid?
SilverSpring
Posts: 110
Joined: Tue Feb 27, 2007 9:43 pm
Contact:

Post by SilverSpring »

The function only accepts 44100 and 48000, gives error otherwise.
User avatar
dot_blank
Posts: 498
Joined: Wed Sep 28, 2005 8:47 am
Location: Brasil

Post by dot_blank »

wonderful !! so 48kHz OGG playback is now possible :)
thanx to you cooleyes keep it up !
10011011 00101010 11010111 10001001 10111010
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

Smaller frequencys can easily be done by simple sample doubling/quadrupling.
Nice find there cooleyes :)
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

There are plenty of rate resamplers out there. The trick is making it sound as good as possible without using too much CPU time. The code can be found everywhere because the vast majority of PC sound cards use fix rate playback (the most common being 48KHz).
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

But you don't need any heavy math for getting 22.050/11.025 or 24.000/12.000Hz when you can playback 44100 and 48000 on hardware.
You just need to double/quadruple every single sample and you're done.
The big problem with playing 48000 or multiples Hz data, requiring fancy sample rate converting was only until now.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

But you don't need any heavy math for getting 22.050/11.025 or 24.000/12.000Hz when you can playback 44100 and 48000 on hardware.
You just need to double/quadruple every single sample and you're done.
Unless you care about the resulting signal quality :)
Doing a zero-order hold like this will result in some pretty bad aliasing artifacts. A first-order hold (linear interpolation) would be a little better. Really, using something like libsamplerate would make more sense.
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

Hi, does someone know the correct nid for the 3.90 firmware?

I think it might be one of this (return 0), but i can't play a custom 48khz mp3 :

//IMPORT_FUNC "sceAudio_driver",0x2533CE02,sceAudioSetFrequency // Do not seems
//IMPORT_FUNC "sceAudio_driver",0x9A34BC0D,sceAudioSetFrequency
//IMPORT_FUNC "sceAudio_driver",0xA1B19554,sceAudioSetFrequency
//IMPORT_FUNC "sceAudio_driver",0xA8B12BF0,sceAudioSetFrequency
//IMPORT_FUNC "sceAudio_driver",0xD5CE71B8,sceAudioSetFrequency // Do not seems
cooleyes
Posts: 123
Joined: Thu May 18, 2006 3:30 pm

Post by cooleyes »

Cpasjuste wrote:Hi, does someone know the correct nid for the 3.90 firmware?

I think it might be one of this (return 0), but i can't play a custom 48khz mp3 :

//IMPORT_FUNC "sceAudio_driver",0x2533CE02,sceAudioSetFrequency // Do not seems
//IMPORT_FUNC "sceAudio_driver",0x9A34BC0D,sceAudioSetFrequency
//IMPORT_FUNC "sceAudio_driver",0xA1B19554,sceAudioSetFrequency
//IMPORT_FUNC "sceAudio_driver",0xA8B12BF0,sceAudioSetFrequency
//IMPORT_FUNC "sceAudio_driver",0xD5CE71B8,sceAudioSetFrequency // Do not seems

Code: Select all

	.set noreorder

#include "pspimport.s"

	IMPORT_START	"sceAudio_driver",0x00010000
	IMPORT_FUNC	"sceAudio_driver",0x442588EB,sceAudioSetFrequency371
	IMPORT_FUNC	"sceAudio_driver",0x9A34BC0D,sceAudioSetFrequency380
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You should probably use the old value and rely on the NID resolver. Remember that this is a kernel-level call and should be put into an external kernel-mode prx to be called from the user app. There's a thread on doing stuff like that, or you can look at the code for PMP Player Advance.

Don't forget that your user-mode app must also be a PRX (set BUILD_PRX in the makefile) to load a kernel-mode external prx lib.
Post Reply