NVDSP icon indicating copy to clipboard operation
NVDSP copied to clipboard

can i use directly with lib `FreeStreamer` to process audio

Open satishVekariya opened this issue 4 years ago • 7 comments

https://github.com/muhku/FreeStreamer Actually i'm trying apply gain to particular frequency

satishVekariya avatar Feb 18 '20 12:02 satishVekariya

Hi, I also saw your email, but since others might have the same question, I will answer here.

Comparing FreeStreamer to Novocaine, I see that both use "kAudioFormatLinearPCM", so in FreeStreamer it seems you should use FSPCMAudioStreamDelegate. It sounds like you are doing that already though.

If you can access the raw samples as floats, it should work. Is there a specific error message you are getting?

bartolsthoorn avatar Feb 20 '20 12:02 bartolsthoorn

What i try is:

lazy var hp:NVPeakingEQFilter = {
        let f = NVPeakingEQFilter.init(samplingRate: 44100)!
        f.q = 2
        f.centerFrequency = 16000
        f.g = 2
        return f
    }()
    func audioStream(_ audioStream: FSAudioStream!, samplesAvailable samples: UnsafeMutablePointer<AudioBufferList>!, frames: UInt32, description: AudioStreamPacketDescription) {
        let float: UnsafeMutablePointer<Float>? = samples.pointee.mBuffers.mData?.assumingMemoryBound(to: Float.self)

        hp.filterData(float, numFrames: frames, numChannels: samples.pointee.mBuffers.mNumberChannels)
    }

if i try above code without any lib modification, it's doing nothing. if i try above code with little modification in FreeSteamer file: audio_stream.cpp, L:1715, i get one channel block and other channel produce noise only, there is no sound!!

modification -> https://github.com/canopas/FreeStreamer/tree/satish/eq

        const UInt32 nFrames = outputBufferList.mBuffers[0].mDataByteSize / THIS->m_dstFormat.mBytesPerFrame;
        if (THIS->m_delegate) {
            THIS->m_delegate->samplesAvailable(&outputBufferList, nFrames, description);
        }
        
        // This blocks until the queue has been able to consume the packets
        THIS->audioQueue()->handleAudioPackets(outputBufferList.mBuffers[0].mDataByteSize,
                                         outputBufferList.mNumberBuffers,
                                         outputBufferList.mBuffers[0].mData,
                                         &description);
        
//        const UInt32 nFrames = outputBufferList.mBuffers[0].mDataByteSize / THIS->m_dstFormat.mBytesPerFrame;
        
//        if (THIS->m_delegate) {
//            THIS->m_delegate->samplesAvailable(&outputBufferList, nFrames, description);
//        }

satishVekariya avatar Feb 24 '20 05:02 satishVekariya

without lib modification i get error like:

LuxeRadio(13191,0x1172105c0) malloc: Incorrect checksum for freed object 0x7f9f4d97c000: probably modified after being freed.
Corrupt value: 0xffffffffffe76270
LuxeRadio(13191,0x1172105c0) malloc: *** set a breakpoint in malloc_error_break to debug

or

objc[13270]: Hash table corrupted. This is probably a memory error somewhere. (table at 0x110b7f808, buckets at 0x7fecbe9c3c00 (8192 bytes), 512 buckets, 252 entries, 67 tombstones, data 0xfffffffbffffffe6 0xfffffffbffffffe6 0xffff9fffffffffe6 0xffff9fffffffffe6)

satishVekariya avatar Feb 24 '20 05:02 satishVekariya

Thank you for sharing the details. I have never used Swift, so that part is difficult for me to follow, but I assume you are sure that the NVPeakingEQFilter is allocated properly and not freed in between buffers / in between hp.filterData calls.

It seems the FreeStreamer samples are in int16_t, did you check that? I found this example: https://github.com/muhku/FreeStreamer/blob/master/Additions/FSFrequencyDomainAnalyzer.m#L207 Here, similar vDSP calls are used as within NVDSP, so you could use it as a starting point instead, did you take a look at this code?

bartolsthoorn avatar Feb 24 '20 12:02 bartolsthoorn

Yes, this example is for analysing purpose and not for processing purpose

https://github.com/muhku/FreeStreamer/blob/master/FreeStreamer/FreeStreamer/audio_stream.cpp#L1655

https://github.com/muhku/FreeStreamer/blob/master/FreeStreamer/FreeStreamer/audio_stream.h#L161

satishVekariya avatar Feb 24 '20 13:02 satishVekariya

@satishVekariya Do you apply gain to FreeStreamer?

iatnam-ios avatar Oct 05 '20 03:10 iatnam-ios

Yes, https://github.com/canopas/FreeStreamer/tree/dev-version-five

On Mon 5 Oct, 2020, 9:14 AM iatnam-ios, [email protected] wrote:

@satishVekariya https://github.com/satishVekariya Do you apply gain to FreeStreamer?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bartolsthoorn/NVDSP/issues/41#issuecomment-703380470, or unsubscribe https://github.com/notifications/unsubscribe-auth/AECN6VHUUSNJWUCEZBAI6N3SJE6KDANCNFSM4KXDH6CA .

satishVekariya avatar Oct 05 '20 14:10 satishVekariya