Lines Matching +full:block +full:- +full:copy

1 // SPDX-License-Identifier: GPL-2.0-or-later
22 * allocate a sample block and copy data from userspace
36 emu = rec->hw; in snd_emu10k1_sample_new()
38 return -EINVAL; in snd_emu10k1_sample_new()
40 if (sp->v.size == 0) { in snd_emu10k1_sample_new()
41 dev_dbg(emu->card->dev, in snd_emu10k1_sample_new()
42 "emu: rom font for sample %d\n", sp->v.sample); in snd_emu10k1_sample_new()
47 sp->v.end -= sp->v.start; in snd_emu10k1_sample_new()
48 sp->v.loopstart -= sp->v.start; in snd_emu10k1_sample_new()
49 sp->v.loopend -= sp->v.start; in snd_emu10k1_sample_new()
50 sp->v.start = 0; in snd_emu10k1_sample_new()
53 sampleend = sp->v.end; in snd_emu10k1_sample_new()
54 if (sampleend > sp->v.size) in snd_emu10k1_sample_new()
55 sampleend = sp->v.size; in snd_emu10k1_sample_new()
56 loopend = sp->v.loopend; in snd_emu10k1_sample_new()
61 if (sp->v.loopstart >= sp->v.loopend) in snd_emu10k1_sample_new()
62 swap(sp->v.loopstart, sp->v.loopend); in snd_emu10k1_sample_new()
65 truesize = sp->v.size + BLANK_HEAD_SIZE; in snd_emu10k1_sample_new()
68 if (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP|SNDRV_SFNT_SAMPLE_REVERSE_LOOP)) in snd_emu10k1_sample_new()
69 loopsize = sp->v.loopend - sp->v.loopstart; in snd_emu10k1_sample_new()
72 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_NO_BLANK) in snd_emu10k1_sample_new()
75 /* try to allocate a memory block */ in snd_emu10k1_sample_new()
77 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) in snd_emu10k1_sample_new()
79 sp->block = snd_emu10k1_synth_alloc(emu, blocksize); in snd_emu10k1_sample_new()
80 if (sp->block == NULL) { in snd_emu10k1_sample_new()
81 dev_dbg(emu->card->dev, in snd_emu10k1_sample_new()
84 return -ENOSPC; in snd_emu10k1_sample_new()
87 sp->v.truesize = blocksize; in snd_emu10k1_sample_new()
92 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) in snd_emu10k1_sample_new()
95 return -EINVAL; in snd_emu10k1_sample_new()
96 snd_emu10k1_synth_bzero(emu, sp->block, offset, size); in snd_emu10k1_sample_new()
99 /* copy start->loopend */ in snd_emu10k1_sample_new()
101 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) in snd_emu10k1_sample_new()
104 return -EINVAL; in snd_emu10k1_sample_new()
105 if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size)) { in snd_emu10k1_sample_new()
106 snd_emu10k1_synth_free(emu, sp->block); in snd_emu10k1_sample_new()
107 sp->block = NULL; in snd_emu10k1_sample_new()
108 return -EFAULT; in snd_emu10k1_sample_new()
115 if (sp->v.mode_flags & (SNDRV_SFNT_SAMPLE_BIDIR_LOOP|SNDRV_SFNT_SAMPLE_REVERSE_LOOP)) { in snd_emu10k1_sample_new()
116 /* copy loop in reverse */ in snd_emu10k1_sample_new()
117 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) { in snd_emu10k1_sample_new()
119 unsigned short *wblock = (unsigned short*)block; in snd_emu10k1_sample_new()
122 return -EINVAL; in snd_emu10k1_sample_new()
124 wblock[woffset + i] = wblock[woffset - i -1]; in snd_emu10k1_sample_new()
128 return -EINVAL; in snd_emu10k1_sample_new()
130 block[offset + i] = block[offset - i -1]; in snd_emu10k1_sample_new()
135 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_BIDIR_LOOP) { in snd_emu10k1_sample_new()
136 sp->v.loopend += loopsize; in snd_emu10k1_sample_new()
138 sp->v.loopstart += loopsize; in snd_emu10k1_sample_new()
139 sp->v.loopend += loopsize; in snd_emu10k1_sample_new()
142 sp->v.end += loopsize; in snd_emu10k1_sample_new()
146 /* loopend -> sample end */ in snd_emu10k1_sample_new()
147 size = sp->v.size - loopend; in snd_emu10k1_sample_new()
149 return -EINVAL; in snd_emu10k1_sample_new()
150 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) in snd_emu10k1_sample_new()
152 if (snd_emu10k1_synth_copy_from_user(emu, sp->block, offset, data, size)) { in snd_emu10k1_sample_new()
153 snd_emu10k1_synth_free(emu, sp->block); in snd_emu10k1_sample_new()
154 sp->block = NULL; in snd_emu10k1_sample_new()
155 return -EFAULT; in snd_emu10k1_sample_new()
161 snd_emu10k1_synth_bzero(emu, sp->block, offset, blocksize - offset); in snd_emu10k1_sample_new()
163 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_NO_BLANK) { in snd_emu10k1_sample_new()
165 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_SINGLESHOT) { in snd_emu10k1_sample_new()
166 sp->v.loopstart = sp->v.end + BLANK_LOOP_START; in snd_emu10k1_sample_new()
167 sp->v.loopend = sp->v.end + BLANK_LOOP_END; in snd_emu10k1_sample_new()
172 if (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_UNSIGNED) { in snd_emu10k1_sample_new()
173 /* unsigned -> signed */ in snd_emu10k1_sample_new()
174 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) { in snd_emu10k1_sample_new()
175 unsigned short *wblock = (unsigned short*)block; in snd_emu10k1_sample_new()
180 block[i] ^= 0x80; in snd_emu10k1_sample_new()
187 if (! (sp->v.mode_flags & SNDRV_SFNT_SAMPLE_8BITS)) in snd_emu10k1_sample_new()
189 sp->v.start += start_addr; in snd_emu10k1_sample_new()
190 sp->v.end += start_addr; in snd_emu10k1_sample_new()
191 sp->v.loopstart += start_addr; in snd_emu10k1_sample_new()
192 sp->v.loopend += start_addr; in snd_emu10k1_sample_new()
198 * free a sample block
206 emu = rec->hw; in snd_emu10k1_sample_free()
208 return -EINVAL; in snd_emu10k1_sample_free()
210 if (sp->block) { in snd_emu10k1_sample_free()
211 snd_emu10k1_synth_free(emu, sp->block); in snd_emu10k1_sample_free()
212 sp->block = NULL; in snd_emu10k1_sample_free()