Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Why should channel_count be compare to sample_count? (Read 8009 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Why should channel_count be compare to sample_count?

Code: [Select]
// Process chunk.
    virtual bool on_chunk(audio_chunk * chunk, abort_callback & p_abort) {
        unsigned channel_count = chunk->get_channels();
        t_size sample_count = chunk->get_sample_count();

        if (channel_count != m_last_sample.get_size()) {
            // number of channels has changed - (re)initialize "history"
            m_last_sample.set_size(channel_count);
            m_last_sample.fill<audio_sample>(0);
        }

        audio_sample * current = chunk->get_data();

        for (t_size sample = 0; sample < sample_count; sample++) {
            for (unsigned channel = 0; channel < channel_count; channel++) {
                audio_sample temp = current[0];
                audio_sample delta = temp - m_last_sample[channel];
                current[0] += delta * m_factor;
                m_last_sample[channel] = temp;
                current++;
            }
        }

        // Add (modified) input chunk to output.
        return true;
    }


Why should channel_count be compare to sample_count?
As far as I read the codes, the "m_last_sample.get_size()" call finally return the buffer size(here is number of audio samples).
Is this a bug?

Why should channel_count be compare to sample_count?

Reply #1
I don't see any line in that code where channel_count is compared to sample_count.
It's only audiophile if it's inconvenient.

Why should channel_count be compare to sample_count?

Reply #2
I don't see any line in that code where channel_count is compared to sample_count.


here it is. get_size() will return the size of the audio sample buffer, afai read the codes.
Code: [Select]
if (channel_count != m_last_sample.get_size()) {

Why should channel_count be compare to sample_count?

Reply #3
[font= "Courier New"]m_last_sample[/font] array has [font= "Courier New"]channel_count[/font] elements, it contains the previous sample of each channel. See also:
Code: [Select]
            m_last_sample.set_size(channel_count);
...
                m_last_sample[channel] = temp;
Full-quoting makes you scroll past the same junk over and over.

Why should channel_count be compare to sample_count?

Reply #4
Thanx, Yirkha.

I may figure the format of the audio samples array like this:
In a chunk of audio samples, all channels of samples(record at a same time) will group together and place in order in the array.
Let's say for a stereo audio stream, the sample stream(return by chunk->get_data()) looks like this:
[sL0][sR0][sL1][sR1][sL2][sR2]....[sLn][sRn]
here 'sL0' stands for the "the sample from the 1st time the Left channel got sampled", etc.
[sLn][sRn] is just sampled at the same time from different channel, I call this "group".

So the m_last_sample is used to store the last "group" processed, so the size of it should be compare to the channel count.

Am I right?

Why should channel_count be compare to sample_count?

Reply #5
Yes this is how both chunks and m_last_sample is used, and why it's defined as an array. If you have mono or multi-channel audio, you need to resize it to fit the number of channels. Chunk size depends on the input format. If you want to see how a 2nd order IIR filter can be implemented, you can take a look here


Why should channel_count be compare to sample_count?

Reply #7
Yes this is how both chunks and m_last_sample is used, and why it's defined as an array. If you have mono or multi-channel audio, you need to resize it to fit the number of channels. Chunk size depends on the input format. If you want to see how a 2nd order IIR filter can be implemented, you can take a look here


Thanx for your comfirm and infomation.

[sLn][sRn] is just sampled at the same time from different channel, I call this "group".
This is often called a "frame".


"frame" is another concept that I don't understand. I just heard from someone yesterday, a frame stands for "1/75 second. for CD, it's 44100/75 = 588 samples/frame.". Why there's two different definitions for "frame"?

Why should channel_count be compare to sample_count?

Reply #8
How is that two different definitions? 
elevatorladylevitateme

Why should channel_count be compare to sample_count?

Reply #9
How is that two different definitions? 


[sL0][sR0] = 1 frame
or
[sL0][sR0][sL1][sR1][sL2][sR2]...[sL587][sR587] = 1 frame

Which is correct?

Why should channel_count be compare to sample_count?

Reply #10
A frame is a slice of audio, containing all channels.

Why should channel_count be compare to sample_count?

Reply #11
A frame is a slice of audio, containing all channels.


This answer is still unclear to me.
My confusion was described above.

And I wonder if a src component MUST implement additional methods declared in resampler_entry and be registered with resampler_factory_t?

Why should channel_count be compare to sample_count?

Reply #12
Quote
Why there's two different definitions for "frame"?


There are even more definitions: http://www.wordia.com/frame


Why should channel_count be compare to sample_count?

Reply #14
This answer is still unclear to me.
My confusion was described above.
Your confusion comes from the fact that CD Audio standard defines "frame" to be 1/75 s, which is derived from the sector size of 2352 Bytes = 588 * 2 (stereo) * 2 (16 bit) samples at 44.1 kHz sampling rate.

And I wonder if a src component MUST implement additional methods declared in resampler_entry and be registered with resampler_factory_t?
That's not required, a DSP can be a resampler without being registered as one. Implementing this service allows any other component to instantiate your resampler with specified source and target sample rates and perhaps allow the user to use it within that component - imagine a streaming plugin, which allows resampling, allowing the user to use any 3rd party resamplers installed.
Full-quoting makes you scroll past the same junk over and over.

Why should channel_count be compare to sample_count?

Reply #15
Thank you. I've got it.

And another question: does the core run dsp in a new thread rather than main thread? Do I have to take care of the multi-threading?

Why should channel_count be compare to sample_count?

Reply #16
DSPs never run in main thread.

Multiple instances of your DSP may be running at the same time in different threads, for example when playing and converting.

In other words, the state of your DSP should not be stored in global/shared variables.

Why should channel_count be compare to sample_count?

Reply #17
Quote
Do I have to take care of the multi-threading?

Anyone can use DSP in fb2k converter to simultaneously encode several files (maybe during playback), so yes.

Why should channel_count be compare to sample_count?

Reply #18
Thank you.