~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to noatun/noatun/library/noatunarts/StereoVolumeControl_impl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#ifdef HAVE_CONFIG_H
 
3
#include <config.h>
 
4
#endif
 
5
 
 
6
#include <artsflow.h>
 
7
#include <stdsynthmodule.h>
 
8
#include <flowsystem.h>
 
9
#include "noatunarts.h"
 
10
 
 
11
using namespace Arts;
 
12
 
 
13
namespace Noatun
 
14
{
 
15
 
 
16
class StereoVolumeControl_impl : virtual public StereoVolumeControl_skel,
 
17
                                 virtual public StdSynthModule
 
18
{
 
19
        float mPercent;
 
20
public:
 
21
        StereoVolumeControl_impl() : mPercent(1.0)
 
22
        { }
 
23
 
 
24
        /*attribute float scaleFactor;*/
 
25
        void percent(float p) { mPercent=p; }
 
26
        float percent() { return mPercent; }
 
27
 
 
28
        void calculateBlock(unsigned long samples)
 
29
        {
 
30
                float *left=inleft;
 
31
                float *right=inright;
 
32
                float *oleft=outleft;
 
33
                float *oright=outright;
 
34
 
 
35
                register float p=mPercent;
 
36
 
 
37
                float *end=left+samples;
 
38
 
 
39
                while (left<end)
 
40
                {
 
41
                        *oleft=*left * p;
 
42
                        *oright=*right * p;
 
43
 
 
44
                        ++left;
 
45
                        ++right;
 
46
                        ++oleft;
 
47
                        ++oright;
 
48
                }
 
49
        }
 
50
};
 
51
        
 
52
class StereoVolumeControlSSE_impl : virtual public Noatun::StereoVolumeControlSSE_skel,
 
53
                                    virtual public StdSynthModule
 
54
{
 
55
        float mPercent;
 
56
public:
 
57
        StereoVolumeControlSSE_impl() : mPercent(1.0)
 
58
        { }
 
59
 
 
60
        /*attribute float scaleFactor;*/
 
61
        void percent(float p) { mPercent=p; }
 
62
        float percent() { return mPercent; }
 
63
 
 
64
        void calculateBlock(unsigned long samples)
 
65
        {
 
66
#ifdef HAVE_X86_SSE
 
67
                float *left=inleft;
 
68
                float *right=inright;
 
69
                float *oleft=outleft;
 
70
                float *oright=outright;
 
71
 
 
72
                // need to copy the data members to locals to get enough
 
73
                // spare registers (malte)
 
74
                
 
75
                long p = (long)(mPercent*100.0);
 
76
                __asm__ __volatile__(
 
77
                        "pushl $100                       \n"
 
78
                        "fildl (%%esp)                    \n"
 
79
                        "fildl %5                         \n"
 
80
                        "fdivp                            \n" // percent / 100.0
 
81
                        "fstps (%%esp)                    \n"
 
82
                        "movss (%%esp), %%xmm1            \n"
 
83
                        "shufps $0x00, %%xmm1, %%xmm1     \n" // percentage in all of xmm1
 
84
                        "addl $4, %%esp                   \n"
 
85
                        "pushl %4                         \n" // save sample count
 
86
                        "shrl $2, %4                      \n"
 
87
                        "jz .l2                           \n" // samples < 4
 
88
                        "xorl %%ecx, %%ecx                \n"
 
89
 
 
90
                        ".l1:                             \n"
 
91
                        // left
 
92
                        "movups (%0, %%ecx, 8), %%xmm0    \n"
 
93
                        "mulps %%xmm1, %%xmm0             \n"
 
94
                        "movl %2, %%eax                   \n"
 
95
                        "movups %%xmm0, (%%eax, %%ecx, 8) \n"
 
96
                        // right
 
97
                        "movups (%1, %%ecx, 8), %%xmm0    \n"
 
98
                        "mulps %%xmm1, %%xmm0             \n"
 
99
                        "movl %3, %%eax                   \n"
 
100
                        "movups %%xmm0, (%%eax, %%ecx, 8) \n"
 
101
                
 
102
                        "incl %%ecx                       \n"
 
103
                        "incl %%ecx                       \n"
 
104
                        "decl %4                          \n"
 
105
                        "jnz .l1                          \n"
 
106
                        ".l2:                             \n"
 
107
                        "popl %4                          \n" // restore sample count
 
108
                        "andl $3, %4                      \n"
 
109
                        "jz .l4                           \n"
 
110
 
 
111
                        // calculate remaining samples for samples % 4 != 0
 
112
                        "shll $1, %%ecx                   \n"
 
113
                        ".l3:                             \n"
 
114
                        "movss (%0, %%ecx, 4), %%xmm0     \n" // load left
 
115
                        "movss (%1, %%ecx, 4), %%xmm2     \n" // load right
 
116
                        "shufps $0x00, %%xmm2, %%xmm0     \n" // both channels in xmm0
 
117
                        "mulps %%xmm1, %%xmm0             \n"
 
118
                        "movl %2, %%eax                   \n"
 
119
                        "movss %%xmm0, (%%eax, %%ecx, 4)  \n" // store left
 
120
                        "shufps $0x02, %%xmm0, %%xmm0     \n"
 
121
                        "movl %3, %%eax                   \n"
 
122
                        "movss %%xmm0, (%%eax, %%ecx, 4)  \n" // store right
 
123
                        "incl %%ecx                       \n"   
 
124
                        "decl %4                          \n"
 
125
                        "jnz .l3                          \n"
 
126
                        
 
127
                        ".l4:                             \n"
 
128
                        "emms                             \n"
 
129
                        :
 
130
                        : "r" (left),     // %0
 
131
                          "r" (right),    // %1
 
132
                          "m" (oleft),    // %2
 
133
                          "m" (oright),   // %3
 
134
                          "r" (samples),  // %4
 
135
                          "m" (p)         // %5
 
136
                        : "eax", "ecx"
 
137
                );
 
138
#endif
 
139
        }
 
140
};
 
141
 
 
142
REGISTER_IMPLEMENTATION(StereoVolumeControlSSE_impl);
 
143
REGISTER_IMPLEMENTATION(StereoVolumeControl_impl);
 
144
 
 
145
};
 
146